Updated "Tags module required" alerts and implimented the tags modules auto-complete function.
This commit is contained in:
parent
b7d542f8ca
commit
4cfaa3dd4e
@ -18,6 +18,12 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class batchtag_event_Core {
|
class batchtag_event_Core {
|
||||||
|
static function pre_deactivate($data) {
|
||||||
|
if ($data->module == "tag") {
|
||||||
|
$data->messages["warn"][] = t("The BatchTag module requires the Tags module.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static function module_change($changes) {
|
static function module_change($changes) {
|
||||||
// See if the Tags module is installed,
|
// See if the Tags module is installed,
|
||||||
// tell the user to install it if it isn't.
|
// tell the user to install it if it isn't.
|
||||||
|
@ -24,10 +24,17 @@ class batchtag_installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function deactivate() {
|
static function deactivate() {
|
||||||
// Clear the require tags message when metadescription is deactivated.
|
|
||||||
site_status::clear("batchtag_needs_tag");
|
site_status::clear("batchtag_needs_tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function can_activate() {
|
||||||
|
$messages = array();
|
||||||
|
if (!module::is_active("tag")) {
|
||||||
|
$messages["warn"][] = t("The BatchTag module requires the Tags module.");
|
||||||
|
}
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
|
||||||
static function uninstall() {
|
static function uninstall() {
|
||||||
module::delete("batchtag");
|
module::delete("batchtag");
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,15 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#g-batch-tag-form").ready(function() {
|
||||||
|
var url = "<?= url::site("tags") ?>" + "/autocomplete";
|
||||||
|
$("#g-batch-tag-form input:text").autocomplete(
|
||||||
|
url, {
|
||||||
|
max: 30,
|
||||||
|
multiple: true,
|
||||||
|
multipleSeparator: ',',
|
||||||
|
cacheLength: 1
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<?= $batch_tag_form ?>
|
<?= $batch_tag_form ?>
|
@ -25,42 +25,93 @@ class BatchTag_Controller extends Controller {
|
|||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
$input = Input::instance();
|
$input = Input::instance();
|
||||||
|
url::redirect(url::abs_site("batchtag/tagitems2?name={$input->post('name')}&item_id={$input->post('item_id')}&tag_subitems={$input->post('tag_subitems')}&csrf={$input->post('csrf')}"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tagitems2() {
|
||||||
|
// Tag all non-album items in the current album with the specified tags.
|
||||||
|
|
||||||
|
// Prevent Cross Site Request Forgery
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
$input = Input::instance();
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
if (($input->get("batchtag_max") == false) || ($input->get("batchtag_max") == "0")) {
|
||||||
|
$batchtag_max = "50";
|
||||||
|
} else {
|
||||||
|
$batchtag_max = $input->get("batchtag_max");
|
||||||
|
}
|
||||||
|
if ($input->get("batchtag_items_processed") == false) {
|
||||||
|
$batchtag_items_processed = "0";
|
||||||
|
} else {
|
||||||
|
$batchtag_items_processed = $input->get("batchtag_items_processed");
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out if the contents of sub-albums should also be tagged
|
// Figure out if the contents of sub-albums should also be tagged
|
||||||
$str_tag_subitems = $input->post("tag_subitems");
|
$str_tag_subitems = $input->get("tag_subitems");
|
||||||
|
|
||||||
$children = "";
|
$children = "";
|
||||||
if ($str_tag_subitems == false) {
|
if ($str_tag_subitems == false) {
|
||||||
// Generate an array of all non-album items in the current album.
|
// Generate an array of all non-album items in the current album.
|
||||||
$children = ORM::factory("item")
|
$children = ORM::factory("item")
|
||||||
->where("parent_id", "=", $input->post("item_id"))
|
->where("parent_id", "=", $input->get("item_id"))
|
||||||
->where("type", "!=", "album")
|
->where("type", "!=", "album")
|
||||||
->find_all();
|
->find_all();
|
||||||
} else {
|
} else {
|
||||||
// Generate an array of all non-album items in the current album
|
// Generate an array of all non-album items in the current album
|
||||||
// and any sub albums.
|
// and any sub albums.
|
||||||
$item = ORM::factory("item", $input->post("item_id"));
|
$item = ORM::factory("item", $input->get("item_id"));
|
||||||
$children = $item->descendants();
|
$children = $item->descendants();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each item in the album and make sure the user has
|
// Loop through each item in the album and make sure the user has
|
||||||
// access to view and edit it.
|
// access to view and edit it.
|
||||||
|
$children_count = "0";
|
||||||
|
$tag_count = "0";
|
||||||
|
|
||||||
|
//echo Kohana::debug($children);
|
||||||
|
|
||||||
|
echo '<style>.continue { margin: 5em auto; text-align: center; }</style>';
|
||||||
|
|
||||||
foreach ($children as $child) {
|
foreach ($children as $child) {
|
||||||
|
|
||||||
|
if ($tag_count < $batchtag_max) {
|
||||||
|
|
||||||
|
if ($children_count >= $batchtag_items_processed) {
|
||||||
if (access::can("view", $child) && access::can("edit", $child) && !$child->is_album()) {
|
if (access::can("view", $child) && access::can("edit", $child) && !$child->is_album()) {
|
||||||
|
|
||||||
// Assuming the user can view/edit the current item, loop
|
// Assuming the user can view/edit the current item, loop
|
||||||
// through each tag that was submitted and apply it to
|
// through each tag that was submitted and apply it to
|
||||||
// the current item.
|
// the current item.
|
||||||
foreach (explode(",", $input->post("name")) as $tag_name) {
|
foreach (explode(",", $input->get("name")) as $tag_name) {
|
||||||
$tag_name = trim($tag_name);
|
$tag_name = trim($tag_name);
|
||||||
if ($tag_name) {
|
if ($tag_name) {
|
||||||
tag::add($child, $tag_name);
|
tag::add($child, $tag_name);
|
||||||
}
|
}
|
||||||
|
// $tag_count should be inside the foreach loop as it is depending on the number of time tag:add is run
|
||||||
|
$tag_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
echo '<style>.c' . $children_count . ' { display:none; }</style>' . "\n";
|
||||||
|
$children_count++;
|
||||||
|
$batchtag_max_new = $tag_count;
|
||||||
|
echo '<div class="continue c' . $children_count . '"><a href="' . url::abs_site("batchtag/tagitems2?name={$input->get('name')}&item_id={$input->get('item_id')}&tag_subitems={$input->get('tag_subitems')}&batchtag_items_processed=$children_count&batchtag_max=$batchtag_max_new&csrf={$input->get('csrf')}") . '">Continue</a></div>';
|
||||||
|
} else { $children_count++; }
|
||||||
|
|
||||||
|
} else { break; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($tag_count < $batchtag_max) {
|
||||||
// Redirect back to the album.
|
// Redirect back to the album.
|
||||||
$item = ORM::factory("item", $input->post("item_id"));
|
$item = ORM::factory("item", $input->get("item_id"));
|
||||||
url::redirect(url::abs_site("{$item->type}s/{$item->id}"));
|
url::redirect(url::abs_site("{$item->type}s/{$item->id}"));
|
||||||
|
//echo url::abs_site("{$item->type}s/{$item->id}");
|
||||||
|
} else {
|
||||||
|
url::redirect(url::abs_site("batchtag/tagitems2?name={$input->get('name')}&item_id={$input->get('item_id')}&tag_subitems={$input->get('tag_subitems')}&batchtag_items_processed=$children_count&batchtag_max=$batchtag_max&csrf={$input->get('csrf')}"));
|
||||||
|
//echo url::abs_site("batchtag/tagitems2?name={$input->get('name')}&item_id={$input->get('item_id')}&tag_subitems={$input->get('tag_subitems')}&batchtag_items_processed=$children_count&batchtag_max=$batchtag_max&csrf={$input->get('csrf')}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,12 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class batchtag_event_Core {
|
class batchtag_event_Core {
|
||||||
|
static function pre_deactivate($data) {
|
||||||
|
if ($data->module == "tag") {
|
||||||
|
$data->messages["warn"][] = t("The BatchTag module requires the Tags module.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static function module_change($changes) {
|
static function module_change($changes) {
|
||||||
// See if the Tags module is installed,
|
// See if the Tags module is installed,
|
||||||
// tell the user to install it if it isn't.
|
// tell the user to install it if it isn't.
|
||||||
|
@ -24,10 +24,17 @@ class batchtag_installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function deactivate() {
|
static function deactivate() {
|
||||||
// Clear the require tags message when metadescription is deactivated.
|
|
||||||
site_status::clear("batchtag_needs_tag");
|
site_status::clear("batchtag_needs_tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function can_activate() {
|
||||||
|
$messages = array();
|
||||||
|
if (!module::is_active("tag")) {
|
||||||
|
$messages["warn"][] = t("The BatchTag module requires the Tags module.");
|
||||||
|
}
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
|
||||||
static function uninstall() {
|
static function uninstall() {
|
||||||
module::delete("batchtag");
|
module::delete("batchtag");
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,15 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#g-batch-tag-form").ready(function() {
|
||||||
|
var url = "<?= url::site("tags") ?>" + "/autocomplete";
|
||||||
|
$("#g-batch-tag-form input:text").autocomplete(
|
||||||
|
url, {
|
||||||
|
max: 30,
|
||||||
|
multiple: true,
|
||||||
|
multipleSeparator: ',',
|
||||||
|
cacheLength: 1
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<?= $batch_tag_form ?>
|
<?= $batch_tag_form ?>
|
Reference in New Issue
Block a user