1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Ansel_Ajax_Imple_GallerySlugCheck extends Horde_Core_Ajax_Imple
12: {
13: public function attach()
14: {
15:
16: Horde::addScriptFile('slugcheck.js');
17:
18: $url = $this->_getUrl('GallerySlugCheck', 'ansel', array('input' => 'slug'));
19:
20: $js = array();
21: $js[] = "Ansel.ajax['gallerySlugCheck'] = {slugText:'" . $this->_params['slug'] . "', 'url': '" . $url . "', bindTo: '" . $this->_params['bindTo'] . "'};";
22: $js[] = "Event.observe(Ansel.ajax.gallerySlugCheck.bindTo, 'change', checkSlug);";
23:
24: Horde::addInlineScript($js, 'dom');
25: }
26:
27: public function handle($args, $post)
28: {
29: if (empty($args['input'])) {
30: return array('response' => '1');
31: }
32: $slug = Horde_Util::getPost($args['input']);
33: if (empty($slug)) {
34: return array('response' => '1');
35: }
36: $valid = preg_match('/^[a-zA-Z0-9_-]*$/', $slug);
37: if (!$valid) {
38: return array('response' => '0');
39: }
40:
41: $exists = $GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists(null, $slug) ? 0 : 1;
42: return array('response' => $exists);
43: }
44:
45: }
46: