Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
added support for names with non-latin letters in comics
Browse files Browse the repository at this point in the history
Added extra fields to the series creation form to specify custom url
slug for the comic.
  • Loading branch information
pushrbx committed Mar 20, 2016
1 parent 1fe2127 commit 0def7a8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
30 changes: 28 additions & 2 deletions application/controllers/admin/series.php
Expand Up @@ -171,9 +171,22 @@ function serie($stub = NULL, $chapter_id = "")
)
);

$custom_slug = array(array(
_('Custom URL Slug'),
array(
'name' => 'has_custom_slug',
'type' => 'checkbox',
'text' => _('Has Custom URL Slug'),
'help' => _('If you want to have a custom url slug or the comic\'s title is written with non-latin letters tick this.'),
'class' => 'jqslugcb'
)
));
array_splice($table, 2, 0, $custom_slug);

$table = tabler($table);
$data['table'] = $table;

$this->viewdata["extra_script"] = '<script type="text/javascript" src="'.base_url().'assets/js/form-extra.js"></script>';
$this->viewdata["main_content_view"] = $this->load->view("admin/series/series.php", $data, TRUE);
$this->load->view("admin/default.php", $this->viewdata);
}
Expand Down Expand Up @@ -258,15 +271,28 @@ function add_new($stub = "")
'name' => 'licensed',
'type' => 'nation',
'value' => array(),
'help' => _('Insert the nations where the series is licensed in order to limit the availability.')
)
'help' => _('Insert the nations where the series is licensed in order to limit the availability.'),
),
);

$custom_slug = array(array(
_('Custom URL Slug'),
array(
'name' => 'has_custom_slug',
'type' => 'checkbox',
'text' => _('Has Custom URL Slug'),
'help' => _('If you want to have a custom url slug or the comic\'s title is written with non-latin letters tick this.'),
'class' => 'jqslugcb'
)
));
array_splice($table, 2, 0, $custom_slug);

$table = tabler($table, FALSE, TRUE);
$data["form_title"] = _('Add New') . ' ' . _('Series');
$data['table'] = $table;

$this->viewdata["extra_title"][] = _("Series");
$this->viewdata["extra_script"] = '<script type="text/javascript" src="'.base_url().'assets/js/form-extra.js"></script>';
$this->viewdata["main_content_view"] = $this->load->view("admin/form.php", $data, TRUE);
$this->load->view("admin/default.php", $this->viewdata);
}
Expand Down
39 changes: 8 additions & 31 deletions application/models/comic.php
Expand Up @@ -18,8 +18,9 @@ class Comic extends DataMapper
),
'stub' => array(
'rules' => array('stub', 'unique', 'max_length' => 256),
'label' => 'Stub',
'type' => 'input'
'label' => 'URL Slug',
'type' => 'input',
'class' => 'uneditable-input jqslug'
),
'uniqid' => array(
'rules' => array('required', 'max_length' => 256),
Expand Down Expand Up @@ -152,33 +153,6 @@ function help_lang()
$this->validation['customchapter']['help'] = _('Replace the default chapter title with a custom format. Example: "{num}{ord} Stage" returns "2nd Stage"');
}

/**
* This function sets the correct slug for the comic when the user specifies
* a name with non italic letters.
*
* @author pushrbx
* @return void
*/
private function fix_stub_for_foreign_name($input_name)
{
// if (!isset($input_name))
// return;

// if ($this->stub == '_' || preg_match('/^[-\' \p{L}]+$/u', $input_name) === 1)
// {
// $CI = &get_instance();
// $CI->load->helper('inflector');
// if ($input_name != "")
// $this->stub = slugify($input_name);

// if (str_replace(" ", "", $this->stub) == "")
// {
// $this->stub = $this->uniqid;
// }
// }
}


/**
* Overwrite of the get() function to add filters to the search.
* Refer to DataMapper ORM for get() function details.
Expand Down Expand Up @@ -355,7 +329,8 @@ public function add($data = array())
$this->uniqid = uniqid();

// in case the user specified a stub
if (array_key_exists('stub', $data) && isset($data['stub']) && $data['stub'] != "")
if (array_key_exists('has_custom_slug', $data) && $data['has_custom_slug'] == 1
&& isset($data['stub']) && $data['stub'] != '')
$this->to_stub = $data['stub'];

// stub() checks for to_stub and makes a stub.
Expand Down Expand Up @@ -454,11 +429,13 @@ public function update_comic_db($data = array())
// always set the editor name
$this->editor = $this->logged_id();
$input_stub = $data["stub"];
$has_custom_slug = isset($data["has_custom_slug"]) && $data["has_custom_slug"] == 1;

// Unset sensible variables
unset($data["creator"]);
unset($data["editor"]);
unset($data["uniqid"]);
unset($data["has_custom_slug"]);
unset($data["stub"]);

// Allow only admins and mods to arbitrarily change the release date
Expand Down Expand Up @@ -490,7 +467,7 @@ public function update_comic_db($data = array())
}

// stub changed by user
if ($input_stub != "" && ($this->stub != $input_stub || $old_stub != $input_stub))
if ($has_custom_slug & $input_stub != "" && ($this->stub != $input_stub || (isset($old_stub) && $old_stub != $input_stub)))
{
$this->stub = $input_stub;
$this->stub = $this->stub();
Expand Down
4 changes: 4 additions & 0 deletions application/views/admin/default.php
Expand Up @@ -105,6 +105,10 @@ function addField(e)
});
});
</script>
<?php
if (isset($extra_script))
echo $extra_script;
?>
<script type="text/javascript">jQuery().alert();</script>
</head>

Expand Down
19 changes: 19 additions & 0 deletions assets/js/form-extra.js
@@ -0,0 +1,19 @@
jQuery(document).ready(function() {
if (jQuery('input.jqslugcb').is(':checked')) {
jQuery('input.jqslug').removeClass('uneditable-input');
jQuery('input.jqslugcb').val(1);
}
else {
jQuery('input.jqslugcb').val(0);
}
jQuery('input.jqslugcb').click(function() {
if (jQuery(this).is(':checked')) {
jQuery('input.jqslug').removeClass('uneditable-input');
jQuery('input.jqslugcb').val(1);
}
else {
jQuery('input.jqslug').addClass('uneditable-input');
jQuery('input.jqslugcb').val(0);
}
});
});

0 comments on commit 0def7a8

Please sign in to comment.