Added support for adding albums remotely
This commit is contained in:
parent
a7851a9a97
commit
7451323165
@ -52,12 +52,27 @@ class G3_Handlers_Controller extends Controller {
|
||||
|
||||
public function add($type) {
|
||||
$path = $this->input->get("path");
|
||||
$form = g3_client::get_form($type, true);
|
||||
$result = array();
|
||||
if ($_POST) {
|
||||
$form->errors["form_error"] = "Add $type not implemented.";
|
||||
$result = "error";
|
||||
unset($_POST["submit"]);
|
||||
$_POST["name"] = empty($_POST["name"]) ? $_POST["title"] : $_POST["name"];
|
||||
$_POST["name"] = g3_client::sanitize_filename($_POST["name"]);
|
||||
$_POST["slug"] = empty($_POST["slug"]) ? $_POST["title"] : $_POST["slug"];
|
||||
$_POST["slug"] = g3_client::sanitize_slug($_POST["slug"]);
|
||||
$result = G3Remote::instance()->add_resource("gallery/$path/{$_POST['slug']}", $_POST);
|
||||
if ($result->status == "OK") {
|
||||
$form = null;
|
||||
$result = "success";
|
||||
} else {
|
||||
$form = g3_client::get_form($type, true, $path, (object)$_POST);
|
||||
foreach (array_keys($_POST) as $field) {
|
||||
if (isset($result->fields->$field)) {
|
||||
$form->errors[$field] = $result->fields->$field;
|
||||
}
|
||||
}
|
||||
$result = "display";
|
||||
}
|
||||
} else {
|
||||
$form = g3_client::get_form($type, true, $path);
|
||||
$result = "display";
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
class g3_client_Core {
|
||||
static function get_form($type, $add_form, $path, $data=null) {
|
||||
$form = new stdClass();
|
||||
$form->adding = $add_form;
|
||||
$form->form = array("title" => (object)array("value" => "", "label" => "Title"),
|
||||
"name" => (object)array("value" => "", "label" => "Name"),
|
||||
"description" => (object)array("value" => "", "label" => "Description"),
|
||||
@ -49,7 +50,8 @@ class g3_client_Core {
|
||||
$json = (object)array("result" => $result);
|
||||
if ($result != "success") {
|
||||
$json->form = new View("edit.html");
|
||||
$json->form->title = "Update " . ucwords($type);
|
||||
$json->form->title = ($form->adding ? "Add " : "Update ") . ucwords($type);
|
||||
$json->form->url = $form->adding ? "add" : "edit";
|
||||
$json->form->path = $path;
|
||||
$json->form->type = $type;
|
||||
$json->form->form = (object)$form->form;
|
||||
@ -62,4 +64,25 @@ class g3_client_Core {
|
||||
|
||||
return json_encode($json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a filename into something safe
|
||||
* @param string $filename
|
||||
* @return string sanitized filename
|
||||
*/
|
||||
static function sanitize_filename($filename) {
|
||||
$filename = empty($filename) ? $title : $filename;
|
||||
$filename = strtr($filename, " ", "_");
|
||||
$filename = preg_replace("/\..*?$/", "", $filename);
|
||||
return preg_replace("/ +/", " ", $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Santize the input url into something safe we can us as the url component.
|
||||
* @param string $filename
|
||||
*/
|
||||
static function sanitize_slug($uri) {
|
||||
$result = preg_replace("/[^A-Za-z0-9-_]+/", "-", $uri);
|
||||
return trim($result, "-");
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<div id="wc-edit">
|
||||
<?= form::open("edit_{$type}?path=$path") ?>
|
||||
<?= form::open("{$url}_{$type}?path=$path") ?>
|
||||
<fieldset>
|
||||
<legend style="display: none"><?= $title ?></legend>
|
||||
<ul>
|
||||
|
Reference in New Issue
Block a user