Example #1
0
 public function __set($prop, $value)
 {
     if ('name' == $prop) {
         $value = url::title($value);
     }
     parent::__set($prop, $value);
 }
Example #2
0
 public static function radio($name, $value = NULL, $checked = FALSE, array $attributes = NULL)
 {
     if (!isset($attributes['id']) and self::$auto_id) {
         $attributes['id'] = 'field-' . $name . '-' . url::title($value);
     }
     return parent::radio($name, $value, $checked, $attributes) . PHP_EOL;
 }
Example #3
0
 public function action_index()
 {
     $this->template->content = View::factory('admin/projects/create')->bind('post', $post)->bind('errors', $errors)->bind('associates', $assoc);
     $assoc = DB::query(Database::SELECT, 'SELECT id, name FROM associates ORDER BY name')->execute()->as_array('id', 'name');
     // Add an option for "no associate"
     arr::unshift($assoc, 0, '- none -');
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('title', 'not_empty')->rule('title', 'regex', array('/^[\\pL\\pP\\s]{4,255}$/iu'))->rule('associate_id', 'not_empty')->rule('associate_id', 'in_array', array(array_keys($assoc)))->rule('completed', 'not_empty')->rule('completed', 'date')->rule('website', 'regex', array('#^https?://.+$#'));
     if ($post->check($errors)) {
         if (empty($post['associate_id'])) {
             // Make the associate NULL
             $post['associate_id'] = NULL;
             // Use only the title for the slug
             $post['slug'] = url::title($post['title']);
         } else {
             // Use the title with associate for the slug
             $post['slug'] = url::title($post['title']) . '/with/' . url::title($assoc[$post['associate_id']]);
         }
         if (empty($post['website'])) {
             // Make the website value NULL
             $post['website'] = NULL;
         }
         // Get the values of the array
         $values = $post->as_array();
         // Convert the completed date into a timestamp
         $values['completed'] = strtotime($values['completed']);
         $query = DB::query(Database::INSERT, 'INSERT INTO projects (title, associate_id, completed, website, slug) VALUES (:values)')->bind(':values', $values)->execute();
         // Set a cookie message
         cookie::set('message', 'Created new project with an ID of ' . $query);
         // Redirect back to the same page
         $this->request->redirect(url::site($this->request->uri));
     }
 }
Example #4
0
 public function __set($key, $value)
 {
     if ($key === 'tags') {
         // Set tag to url-safe format
         $value = url::title($value);
     }
     parent::__set($key, $value);
 }
Example #5
0
 /**
  * TODO: Add check to enforce ajax request
  */
 public function action_slug()
 {
     $title = isset($_POST['title']) ? $_POST['title'] : '';
     $slug = url::title($title);
     /**
      * TODO: Add check to ensure unique slug
      */
     $this->request->response = json_encode(array('slug' => $slug));
 }
Example #6
0
 public static function make_url_identifier(Comment_Model $comment)
 {
     $url_identifier = '';
     if (isset($comment->commented_object->url_identifier)) {
         $url_identifier = $comment->commented_object->url_identifier;
     } else {
         $url_identifier = url::title($comment->underlying_object_name . "-" . $comment->underlying_object_id . "-" . $comment->title);
     }
     return $url_identifier;
 }
Example #7
0
 public function set_tags($tags_string)
 {
     $tag_strings = preg_split('/[^\\w\\-\\.\\_]+/', $tags_string);
     $tags = array();
     foreach ($tag_strings as $tag_string) {
         $tag = ORM::factory('tag', url::title($tag_string));
         if (!$tag->loaded) {
             $tag->name = $tag_string;
             $tag->save();
         }
         $tags[] = $tag->id;
     }
     $this->__set('tags', $tags);
 }
Example #8
0
 public static function unique_title($title)
 {
     $uri = url::title($title);
     $result = Database::instance()->select('uri')->like('uri', $uri . '%', FALSE)->get('blog_posts');
     if (count($result) > 0) {
         $max = 0;
         foreach ($result as $row) {
             $suffix = substr($row->uri, strlen($uri) + 1);
             if (ctype_digit($suffix) and $suffix > $max) {
                 $max = $suffix;
             }
         }
         if ($max === 0) {
             $uri .= '-2';
         } else {
             $uri .= '-' . ($max + 1);
         }
     }
     return $uri;
 }
Example #9
0
File: roles.php Project: anqqa/Anqh
 /**
  * Single role view
  *
  * @param  string  $role_id
  * @param  string  $action
  */
 public function role($role_id, $action = null)
 {
     if ($action) {
         switch ($action) {
             // Delete role
             case 'delete':
                 $this->_role_delete($role_id);
                 return;
         }
     }
     $this->history = false;
     $role = new Role_Model((int) $role_id);
     $form_values = $role->as_array();
     $form_errors = $errors = array();
     // Check post
     if ($post = $this->input->post()) {
         $role->name = $post['name'];
         $role->description = $post['description'];
         try {
             $role->save();
             url::redirect('/roles');
         } catch (ORM_Validation_Exception $e) {
             $form_errors = $e->validation->errors();
         }
         $form_values = arr::overwrite($form_values, $post);
     }
     // show form
     if ($role->id) {
         $this->breadcrumb[] = html::anchor('role/' . url::title($role->id, $role->name), html::specialchars($role->name));
         $this->page_title = text::title($role->name);
         $this->page_actions[] = array('link' => 'role/' . url::title($role->id, $role->name) . '/delete', 'text' => __('Delete role'), 'class' => 'role-delete');
     } else {
         $this->page_title = __('Role');
     }
     if (empty($errors)) {
         widget::add('main', View_Mod::factory('roles/role_edit', array('values' => $form_values, 'errors' => $form_errors)));
     } else {
         $this->_error(Kohana::lang('generic.error'), $errors);
     }
 }
Example #10
0
 public function edit($album_id = NULL)
 {
     $album = new Album_Model($album_id);
     if (!$album->id) {
         Event::run('system.404');
     }
     $this->template->content = new View('admin/album/form');
     $this->template->content->errors = '';
     $this->template->content->action = 'Edit';
     if ($_POST) {
         try {
             $old_name = $album->album_name;
             $album->set_fields($_POST);
             $album->url_name = url::title($_POST['album_name']);
             $album->save();
             // Rename the album folder too
             rename(APPPATH . 'views/media/photos/' . url::title($old_name), APPPATH . 'views/media/photos/' . $album->url_name);
             url::redirect('admin/album/index');
         } catch (Kohana_User_Exception $e) {
             $this->template->content->errors = $e;
         }
     }
     $this->template->content->album = $album;
 }
Example #11
0
 /**
  * Edit venue
  *
  * @param  integer|string  $venue_id
  * @param  integer|string  $category_id
  */
 public function _venue_edit($venue_id = false, $category_id = false)
 {
     $this->history = false;
     $venue = new Venue_Model((int) $venue_id);
     // Check access
     if (!($venue->loaded() && $venue->has_access(Venue_Model::ACCESS_EDIT)) && !(!$venue->loaded() && $this->visitor->logged_in(array('admin', 'venue moderator', 'venue')))) {
         url::back('venues');
     }
     $errors = $form_errors = array();
     $form_values = $venue->as_array();
     // check post
     if (request::method() == 'post') {
         $post = array_merge($this->input->post(), $_FILES);
         $extra = array('author_id' => $this->user->id);
         // got address, get geocode
         if (!empty($post['address']) && !empty($post['city_name'])) {
             list($extra['latitude'], $extra['longitude']) = Gmap::address_to_ll(implode(', ', array($post['address'], $post['zip'], $post['city_name'])));
         }
         if (csrf::valid() && $venue->validate($post, true, $extra)) {
             // handle logo upload
             if (isset($post->logo) && empty($post->logo['error'])) {
                 $logo = Image_Model::factory('venues.logo', $post->logo, $this->user->id);
                 if ($logo->id) {
                     $venue->add($logo);
                     $venue->default_image_id = $logo->id;
                     $venue->save();
                 }
             }
             // handle picture uploads
             foreach (array($post->picture1, $post->picture2) as $picture) {
                 if (isset($picture) && empty($picture['error'])) {
                     $image = Image_Model::factory('venues.image', $picture, $this->user->id);
                     if ($image->id) {
                         $venue->add($image);
                         $venue->save();
                     }
                 }
             }
             // update tags
             $venue->remove(ORM::factory('tag'));
             if (!empty($post->tags)) {
                 foreach ($post->tags as $tag_id => $tag) {
                     $venue->add(ORM::factory('tag', $tag_id));
                 }
             }
             url::redirect(url::model($venue));
         } else {
             $form_errors = $post->errors();
         }
         $form_values = arr::overwrite($form_values, $post->as_array());
     }
     // editing old?
     if ($venue_id) {
         if ($venue->has_access(Venue_Model::ACCESS_DELETE)) {
             $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name) . '/delete/?token=' . csrf::token(), 'text' => __('Delete venue'), 'class' => 'venue-delete');
         }
         $this->page_subtitle = __('Edit venue');
         if (!$venue->id) {
             $errors = array('venues.error_venue_not_found');
         } else {
             $venue_category = $venue->venue_category;
         }
     } else {
         $this->page_subtitle = __('Add venue');
         if ($category_id) {
             $venue_category = new Venue_Category_Model((int) $category_id);
             if ($venue_category->id) {
                 $form_values['venue_category_id'] = $venue_category->id;
             } else {
                 $errors = array('venues.error_venue_category_not_found');
             }
         }
     }
     $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name), 'text' => __('Cancel'), 'class' => 'cancel');
     $this->breadcrumb[] = html::anchor('/venues/' . url::title($venue_category->id, $venue_category->name), $venue_category->name);
     if ($venue->id) {
         $this->breadcrumb[] = html::anchor('/venue/' . url::title($venue->id, $venue->name), $venue->name);
     }
     // show form
     if (empty($errors)) {
         $form = array();
         // tags
         if ($venue_category->tag_group_id) {
             $form['tags'] = $form_values['tags'] = array();
             foreach ($venue_category->tag_group->tags as $tag) {
                 $form['tags'][$tag->id] = $tag->name;
                 if ($venue->has($tag)) {
                     $form_values['tags'][$tag->id] = $tag->name;
                 }
             }
         }
         $venue_categories = ORM::factory('venue_category')->find_all()->select_list('id', 'name');
         $form['venue_category_id'] = $venue_categories;
         widget::add('main', View_Mod::factory('venues/venue_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors)));
         // city autocomplete
         $this->_autocomplete_city();
     } else {
         $this->_error(Kohana::lang('generic.error'), $errors);
     }
     $this->_side_views();
 }
 protected function attach_associated_file($field, $file, $type)
 {
     switch ($type) {
         case 'upload':
         case 'stash':
             $path = $file['tmp_name'];
             $name = $file['name'];
             break;
         case 'copy':
         case 'move':
             $path = $file;
             $name = $file;
             break;
         default:
             throw new Kohana_User_Exception('!!!', '');
     }
     // Get original filename and extension
     $pathinfo = pathinfo($name) + array('extension' => NULL);
     // Limit filename and sanatise
     $filename = text::limit_chars($pathinfo['filename'], 15, '');
     $filename = url::title($filename, '_');
     // Sanatise extension
     $extension = trim(preg_replace('#[^a-z0-9]#', '', strtolower($pathinfo['extension'])));
     $directory = $this->associated_files_path();
     // Check that the directory exists, create it if not
     if (!is_dir($directory)) {
         mkdir($directory, 0777, TRUE);
     }
     // Check it's writable
     if (!is_writable($directory)) {
         throw new Kohana_Exception('upload.not_writable', $directory);
     }
     $prefix = $directory . $this->object[$this->primary_key] . '-' . $field . '-';
     $name = time() . '-' . $filename . ($extension ? ".{$extension}" : '');
     switch ($type) {
         case 'upload':
             move_uploaded_file($path, $prefix . $name);
             break;
         case 'move':
         case 'stash':
             rename($path, $prefix . $name);
             break;
         case 'copy':
             copy($path, $prefix . $name);
             break;
     }
     $this->{$field} = $name;
 }
Example #13
0
?>

<br/>

<?php 
echo url::site('controller/action');
?>

<br/>

<?php 
echo url::site('controller/action', 'ftp');
?>

<br/>

<?php 
echo url::query();
?>

<br/>

<?php 
echo url::query(array('bar' => 'foo'));
?>

<br/>

<?php 
echo url::title('This is my title');
Example #14
0
 /**
  * Makes a heading id from the heading text
  * If any heading share the same name then subsequent headings will have an integer appended
  *
  * @param  string The heading text
  * @return string ID for the heading
  */
 function make_heading_id($heading)
 {
     $id = url::title($heading, '-', TRUE);
     if (isset($this->_heading_ids[$id])) {
         $id .= '-';
         $count = 0;
         while (isset($this->_heading_ids[$id]) and ++$count) {
             $id .= $count;
         }
     }
     return $id;
 }
Example #15
0
 public function edit($id)
 {
     $page = ORM::factory('page', (int) $id);
     if (!$page->loaded) {
         message::error(__('Invalid ID'), 'admin/page');
     }
     $form = Formo::factory()->plugin('csrf')->add_group('type', array('none' => __('Do nothing'), 'module' => __('Load module'), 'redirect' => __('Redirect to')))->add_select('module', module::installed_as_array(), array('value' => $page->target))->add_select('redirect', $page->paths(), array('value' => $page->target))->add('submit', 'submit', array('label' => __('Save')));
     foreach (Kohana::config('locale.languages') as $key => $value) {
         $page_content = ORM::factory('page_content')->where(array('page_id' => $page->id, 'language' => $key))->find();
         $form->add('text', 'title_' . $key, array('label' => __('Title'), 'value' => $page_content->title))->add('text', 'content_' . $key, array('label' => __('Content'), 'value' => $page_content->content))->add_rule('title_' . $key, 'required', __('Please choose a title'));
     }
     if ($form->validate()) {
         $title = array();
         foreach (Kohana::config('locale.languages') as $key => $value) {
             $page_content = ORM::factory('page_content')->where(array('page_id' => $page->id, 'language' => $key))->find();
             if (!$page_content->loaded) {
                 $page_content->page_id = $page->id;
                 $page_content->language = $key;
                 $page_content->date = date("Y-m-d H:i:s");
             }
             $page_content->title = $form->{'title_' . $key}->value;
             $page_content->uri = url::title($form->{'title_' . $key}->value);
             $page_content->content = $form->{'content_' . $key}->value;
             $page_content->modified = date("Y-m-d H:i:s");
             $page_content->save();
             $title[] = $page_content->title;
         }
         $type = NULL;
         $target = NULL;
         /*
          * TODO workaround for:
          * http://projects.kohanaphp.com/boards/5/topics/114
          * and
          * http://projects.kohanaphp.com/issues/1697
          *
          * fixed in Formo 1.2
          *
          */
         $_type = NULL;
         foreach ($form->type->elements as $key => $value) {
             if ($form->type->{$key}->checked) {
                 $_type = $value;
                 break;
             }
         }
         if ($_type == 'redirect') {
             $redirect = trim($form->redirect->value);
             if (!empty($redirect)) {
                 $type = 'redirect';
                 $target = $redirect;
             }
         } elseif ($_type == 'module') {
             $module = trim($form->module->value);
             if (!empty($module)) {
                 $type = 'module';
                 $target = $module;
             }
         }
         $page->type = $type;
         $page->target = $target;
         $page->title = implode(' / ', $title);
         $page->save();
         Cache::instance()->delete_tag('menu');
         Cache::instance()->delete_tag('route');
         message::info(__('Page edited successfully'), 'admin/page');
     }
     $this->template->content = View::factory('page/edit', $form->get(TRUE));
     $this->template->content->page = $page;
     $this->template->content->modules = module::installed();
 }
Example #16
0
foreach ($events as $date => $cities) {
    ?>
	<li class="day">

		<header>
			<?php 
    echo html::box_day($date);
    ?>
		</header>

		<?php 
    foreach ($cities as $city => $events) {
        ?>

		<div class="city city-<?php 
        echo url::title($city);
        ?>
">
			<?php 
        if (!empty($city)) {
            ?>

			<header>
				<h3><?php 
            echo text::title($city);
            ?>
</h3>
			</header>
			<?php 
        }
        ?>
Example #17
0
    /**
     * add a new page into the tree
     *
     * @return void
     * @author Andy Bennett
     */
    public function add()
    {
        $table = steamcore::get_controls_model('pages')->get_table();
        $data = array();
        $data['title'] = "New Page";
        $data['name'] = url::title($data['title']);
        $data["date_added"] = date('Y-m-d H:i:s');
        $data["date_modified"] = date('Y-m-d H:i:s');
        $data["container"] = 1;
        $data["copy"] = '<div class="editablecontent">
							<div class="editable" id="anonymous_element_14">
								Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore  magna aliquyam erat, sed diam voluptua. At vero eos et  accusam et justo duo dolores et ea rebum. Stet clita kasd  gubergren, no sea takimata sanctus est Lorem ipsum dolor  sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing  elitr, sed diam nonumy eirmod tempor invidunt ut labore  et dolore magna aliquyam erat, sed diam voluptua.
							</div>
						</div>';
        $db = new Database();
        $r = $db->insert($table, $data);
        $id = $r->insert_id();
        $db->where('id', $id)->update($table, array('name' => 'page-' . $id));
        echo $id;
    }
Example #18
0
 /**
  * Build filter items
  *
  * @param   ORM_Iterator  $events
  * @return  array
  */
 public function _build_filters(ORM_Iterator $events)
 {
     $filters = array();
     if ($events->count()) {
         $cities = array();
         // Build filter list
         foreach ($events as $event) {
             // Build city
             $city = $event->city_id ? $event->city->city : $event->city_name;
             $filter = url::title($city);
             if (!isset($cities[$filter])) {
                 $cities[$filter] = utf8::ucfirst(utf8::strtolower($city));
             }
         }
         // Drop empty to last
         ksort($cities);
         if (isset($cities[''])) {
             $cities[url::title(__('Elsewhere'))] = utf8::ucfirst(utf8::strtolower(__('Elsewhere')));
             unset($cities['']);
         }
         // Build city filter
         $filters['city'] = array('name' => __('City'), 'filters' => $cities);
     }
     return $filters;
 }
Example #19
0
File: roles.php Project: anqqa/Anqh
<?php

/**
 * Roles list
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2010 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
?>

<ul>
	<?php 
foreach ($roles as $role) {
    ?>
	<li><?php 
    echo html::anchor('/role/' . url::title($role->id, $role->name), $role->name);
    ?>
 - <?php 
    echo html::specialchars($role->description);
    ?>
</li>
	<?php 
}
?>
</ul>
Example #20
0
 public function action_index()
 {
     $this->xslt_stylesheet = 'admin/galleries';
     xml::to_XML(array('admin_page' => 'Galleries'), $this->xml_meta);
     if (!empty($_POST)) {
         if (!empty($_POST['gallery'])) {
             foreach ($_POST['gallery'] as $counter => $gallery_URI) {
                 $contents = Content_Content::get_contents_by_tags(array('gallery' => $gallery_URI, 'type' => 'sort'));
                 if (count($contents)) {
                     list($sort_content_id) = array_keys($contents);
                     list($sort_content_content) = array_values($contents);
                     $content = new Content_Content($sort_content_id);
                     $content->update_content($counter);
                 } else {
                     Content_Content::new_content($counter, array('gallery' => array($gallery_URI), 'type' => array('sort')));
                 }
             }
             foreach ($_POST['category'] as $counter => $category_name) {
                 $contents = Content_Content::get_contents_by_tags(array('category' => $category_name, 'type' => 'sort'));
                 if (count($contents)) {
                     list($sort_content_id) = array_keys($contents);
                     list($sort_content_content) = array_values($contents);
                     $content = new Content_Content($sort_content_id);
                     $content->update_content($counter);
                 } else {
                     Content_Content::new_content($counter, array('category' => array($category_name), 'type' => array('sort')));
                 }
             }
         }
         if (!empty($_POST['new_gallery_name'])) {
             $this->redirect('admin/gallery?uri=' . url::title($_POST['new_gallery_name'], '-', TRUE));
         }
     }
     // Get all galleries
     $galleries = array();
     $gallery_names = array();
     $categories = array();
     foreach (Content_Image::get_tags() as $tag) {
         if ($tag['name'] == 'gallery') {
             foreach ($tag['values'] as $tag_value) {
                 if (!in_array($tag_value, $gallery_names)) {
                     $name = '';
                     $sort = 0;
                     $category = '';
                     // Get some content
                     $contents = Content_Content::get_contents_by_tags(array('gallery' => $tag_value));
                     foreach ($contents as $content) {
                         if ($content['tags']['type'][0] == 'name') {
                             $name = $content['content'];
                         } elseif ($content['tags']['type'][0] == 'sort') {
                             $sort = $content['content'];
                         } elseif ($content['tags']['type'][0] == 'category') {
                             $category = $content['content'];
                         }
                     }
                     if ($name == '') {
                         $name = $tag_value;
                     }
                     if (!in_array($category, $categories)) {
                         $categories[] = $category;
                     }
                     $galleries[] = array('URI' => $tag_value, 'name' => $name, '@sort' => $sort, 'category' => $category);
                 }
                 $gallery_names[] = $tag_value;
             }
         }
     }
     $this->xml_content_galleries = $this->xml_content->appendChild($this->dom->createElement('galleries'));
     xml::to_XML($galleries, $this->xml_content_galleries, 'gallery');
     foreach ($categories as $nr => $category_real_name) {
         if ($category_real_name != '') {
             $sort = 0;
             foreach (Content_Content::get_contents_by_tags(array('category' => $category_real_name, 'type' => 'sort')) as $content) {
                 $sort = $content['content'];
             }
             $categories[$nr . 'category'] = array('URI' => URL::title($category_real_name, '-', TRUE), 'name' => $category_real_name, 'sort' => $sort);
         }
         unset($categories[$nr]);
     }
     $this->xml_content_categories = $this->xml_content->appendChild($this->dom->createElement('categories'));
     xml::to_XML($categories, $this->xml_content_categories);
 }
Example #21
0
 /**
  * Normalize Tag
  *
  * This is a utility function used to take a raw tag and convert it to normalized form.
  * Normalized form is essentially lowercased alphanumeric characters only,
  * with no spaces or special characters.
  *
  * Customize the normalized valid chars with your own set of special characters
  * in regex format within the option 'custom_normalization'. It acts as a filter
  * to let a customized set of characters through.
  *
  * After the filter is applied, the function also lowercases the characters using strtolower
  * in the current locale.
  *
  * The default for normalized_valid_chars is a-zA-Z0-9, or english alphanumeric.
  *
  * @param	string	tag	An individual tag in raw form that should be normalized.
  * @return	string	Returns the tag in normalized form.
  */
 public function normalize_tag($tag)
 {
     if ($this->config['normalize_tags']) {
         if ($this->config['use_kohana_normalization']) {
             $tag = url::title($tag);
         } else {
             $normalized_valid_chars = $this->config['custom_normalization'];
             $tag = preg_replace("/[^{$normalized_valid_chars}]/", "", $tag);
         }
         return strtolower($tag);
     } else {
         return $tag;
     }
 }