[Improvements to the virtual column system - Photo -> Asset - improved documentation tom@wwworldmedia.com**20051031193459] { hunk ./GangplankBase.php 230 - // that works outside of the usual type-guessing mechanism. + // that works outside of the usual type-guessing mechanism. $type refers + // to any of the predefined virtual column types. $data is a set of configurable + // parameters that controls how the virtual column will work - they are + // type-specific. $order_by_clause allows you to specify an alternate order by + // clause to the database when the user sorts by the virtual column hunk ./GangplankBase.php 237 - if (empty($name) || empty($type)) gp_die("addVirtualColumn(): first arg (name) or second arg (type) are blank"); - if (! in_array($type, $this->virtual_column_types)) gp_die("addVirtualColumn($name): '$type' is not a defined virtual column type."); + if (empty($name) || empty($type)) + gp_die("addVirtualColumn(): first arg (name) or second arg (type) are blank"); + + if (! in_array($type, $this->virtual_column_types)) + gp_die("addVirtualColumn($name): '$type' is not a defined virtual column type."); hunk ./GangplankBase.php 245 - if (! call_user_func(array($this, "validateVirtual${type}Data"), $data, $error_text)) + if (! call_user_func(array(&$this, "validateVirtual${type}Data"), $data, &$error_text)) hunk ./GangplankEdit.php 41 - $this->virtual_column_types[] = "Photo"; + $this->virtual_column_types[] = "Asset"; hunk ./GangplankEdit.php 475 - // --[ The "Photo" Virtual Column Type ]-- + // --[ The "Asset" Virtual Column Type ]-- + // + // This is basically an uploadable piece of data -- file, photo, + // document, etc. It is shown in an IMG tag while you edit the document. + // hunk ./GangplankEdit.php 481 - // This is basically an uploadable photo. It is shown in an IMG tag while you - // edit the document. - function renderVirtualPhoto($row, $col) { + function validateVirtualAssetData($data, &$error_text) { + if (empty($data)) + return true; + $valid_opts = array("disallow_downloads", "upload_path", "upload_url", "path_column"); + foreach ($data as $k=>$v) { + if (!in_array($k, $valid_opts)) { + $opts = join(", ", $valid_opts); + $error_text = "Invalid \"$k\" option given -- must be one of ($opts)"; + return false; + } + } + return true; + } + + function renderVirtualAsset($row, $col) { hunk ./GangplankEdit.php 507 - $html .= "No pic has been uploaded yet.
"; + $html .= "Nothing has been uploaded yet.
"; hunk ./GangplankEdit.php 509 - if ($this->photo_preview === true) { - $html .= "\"$name
"; + if (!isset($col["virtual_data"]["disallow_downloads"]) && + $col["virtual_data"]["disallow_downloads"] == 0) { + $html .= "Open asset
"; hunk ./GangplankEdit.php 513 - $html .= "View image
"; + $html .= "Asset has been uploaded.
"; hunk ./GangplankEdit.php 524 - // Save a Photo column - basically processes and moves an upload. - function saveVirtualPhoto($row, $col) { + // Save an Asset column - basically processes and moves an upload. + function saveVirtualAsset($row, $col) { hunk ./GangplankEdit.php 529 - if (empty($uploaded_img_path)) gp_die("saveVirtualPhoto(): No uploaded image path"); - if (empty($uploaded_img_url)) gp_die("saveVirutalPhoto(): No uploaded image URL"); + $options = $col["virtual_data"]; + + if (!empty($options["upload_path"])) + $uploaded_img_path = $col["virtual_data"]["upload_path"]; + if (!empty($options["upload_url"])) + $uploaded_img_url = $col["virtual_data"]["upload_url"]; + + if (empty($uploaded_img_path)) gp_die("saveVirtualAsset(): No uploaded image path"); + if (empty($uploaded_img_url)) gp_die("saveVirutalAsset(): No uploaded image URL"); hunk ./GangplankEdit.php 545 - if (! is_uploaded_file($tmp)) gp_die("saveVirtualPhoto(): Bad upload!"); + if (! is_uploaded_file($tmp)) gp_die("saveVirtualAsset(): Bad upload!"); hunk ./GangplankEdit.php 564 - gp_die("saveVirtualPhoto(): Command failed: 'move_uploaded_file($tmp, $out_fn)'"); + gp_die("saveVirtualAsset(): Command failed: 'move_uploaded_file($tmp, $out_fn)'"); hunk ./GangplankEdit.php 567 - $sql .= "$field = '$out_url', "; + $sql .= "$field = '" . gp_escapeSql($out_url) ."', "; + if (!empty($options["path_column"])) + $sql .= "$options[path_column] = '" . gp_escapeSql($out_fn) . "', "; }