Esempio n. 1
0
File: day.php Progetto: anqh/events
 /**
  * Executed before rendering.
  */
 public function before()
 {
     // Generate section title if none set
     if (is_null($this->title) && $this->date) {
         if ($this->date == date('Y-m-d')) {
             $this->title = __('Today');
             $this->class .= ' today';
         } else {
             if ($this->date == date('Y-m-d', strtotime('tomorrow'))) {
                 $this->title = __('Tomorrow');
                 $this->class .= ' tomorrow';
             } else {
                 $date = Date::split($this->date);
                 $this->title = $date['weekday_short'] . ' ' . $date['day'] . ' ' . $date['month_short'];
             }
         }
     }
     // Add articles
     foreach ((array) $this->events as $city => $events) {
         foreach ($events as $event) {
             $article = new View_Event_Day($event);
             $article->class .= ' city-' . URL::title($city);
             $this->articles[] = $article;
         }
     }
 }
Esempio n. 2
0
 public function action_new()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New field')));
     $this->template->title = __('New Custom Field for Users');
     if ($_POST) {
         if (count(Model_UserField::get_all(FALSE)) > 65) {
             Alert::set(Alert::ERROR, __('You have reached the maximum number of custom fields allowed.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'userfields', 'action' => 'index')));
         }
         $name = URL::title(Core::post('name'));
         if (strlen($name) >= 60) {
             $name = Text::limit_chars($name, 60, '');
         }
         $field = new Model_UserField();
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'show_profile' => Core::post('show_profile') == 'on' ? TRUE : FALSE, 'show_register' => Core::post('show_register') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE);
             if ($field->create($name, Core::post('type'), Core::post('values'), $options)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s created'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s already exists'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'userfields', 'action' => 'index')));
     }
     $this->template->content = View::factory('oc-panel/pages/userfields/new');
 }
Esempio n. 3
0
 /**
  * return the title formatted for the URL
  *
  * @param  string $title
  * 
  */
 public function gen_seotitle($seotitle)
 {
     //in case seotitle is really small or null
     if (strlen($seotitle) < 3) {
         $seotitle = $this->title;
     }
     $seotitle = URL::title($seotitle);
     if ($seotitle != $this->seotitle) {
         $post = new self();
         //find a user same seotitle
         $s = $post->where('seotitle', '=', $seotitle)->limit(1)->find();
         //found, increment the last digit of the seotitle
         if ($s->loaded()) {
             $cont = 2;
             $loop = TRUE;
             while ($loop) {
                 $attempt = $seotitle . '-' . $cont;
                 $post = new self();
                 unset($s);
                 $s = $post->where('seotitle', '=', $attempt)->limit(1)->find();
                 if (!$s->loaded()) {
                     $loop = FALSE;
                     $seotitle = $attempt;
                 } else {
                     $cont++;
                 }
             }
         }
     }
     return $seotitle;
 }
Esempio n. 4
0
 public function action_write()
 {
     $this->template->page_title = 'Write Article';
     $user = new Model_User();
     $session = Session::instance()->get('user');
     $view = View::factory('cp/entries/write');
     $view->author = $users->get_user_by_session_id($session);
     if ($this->request->method() === Request::POST) {
         if (!Security::check($this->request->post('csrf_token'))) {
             throw new HTTP_Exception_401("Bad token!");
         }
         $post_title = $this->request->post('title');
         $post_slug = $this->request->post('slug');
         $post_content = $this->request->post('content');
         $post_author = $this->request->post('author');
         $post_date = time();
         if (empty($post_title) and empty($post_content) and empty($post_author) and empty($post_date)) {
             throw new Exception('Please don`t make empty fields!');
         }
         if (empty($post_slug)) {
             $post_slug = URL::title($post_title, '_');
         }
         $entry = new Model_Entry();
         $data = array('title' => $post_title, 'slug' => $post_slug, 'content' => $post_content, 'author' => $post_author, 'date' => $post_date);
         $insert_entry = $entry->insert_entry($data);
         if (!$insert_entry) {
             throw new Exception('Check if you are connected to database!');
         }
         $this->request->redirect('cp/entries/write/');
     }
     $this->template->content = $view->render();
 }
Esempio n. 5
0
 /**
  * Validation rule for checking a valid token
  *
  * @param   string  $namespace - the token string to check for
  * @return  bool
  */
 public static function valid($namespace = NULL)
 {
     if ($namespace === NULL) {
         $namespace = URL::title(Request::current()->uri());
     }
     return Request::$current->post('csrf_' . $namespace) === self::token($namespace);
 }
Esempio n. 6
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     $loc = new Model_Location();
     // loaded locations
     if (Model_Location::current()->loaded()) {
         $location = Model_Location::current()->id_location;
         // id_location
         //list of children of current location
         // if list_loc dosent have siblings take brothers //
         $list_loc = $loc->where('id_location_parent', '=', $location)->order_by('order', 'asc')->cached()->find_all();
         if (count($list_loc) == 0) {
             $list_loc = $loc->where('id_location_parent', '=', Model_Location::current()->id_location_parent)->order_by('order', 'asc')->cached()->find_all();
         }
         //parent of current location
         $loc_parent_deep = $loc->where('id_location', '=', Model_Location::current()->id_location_parent)->limit(1)->find();
         // array with name and seoname of a location and his parent. Is to build breadcrumb in widget
         $current_and_parent = array('name' => Model_Location::current()->name, 'id' => Model_Location::current()->id_location, 'seoname' => Model_Location::current()->seoname, 'parent_name' => $loc_parent_deep->name, 'id_parent' => $loc_parent_deep->id_location_parent, 'parent_seoname' => $loc_parent_deep->seoname);
     } else {
         $list_loc = $loc->where('id_location_parent', '=', 1)->order_by('order', 'asc')->cached()->find_all();
         $current_and_parent = NULL;
     }
     $this->locations = $this->locations;
     $this->loc_items = $list_loc;
     $this->loc_breadcrumb = $current_and_parent;
     $this->cat_seoname = URL::title(__('all'));
     if (Model_Category::current()->loaded()) {
         $this->cat_seoname = Model_Category::current()->seoname;
     }
 }
Esempio n. 7
0
 public function action_new()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New')));
     $this->template->title = __('New Custom Field for Advertisement');
     //find all, for populating form select fields
     list($categories) = Model_Category::get_all();
     if ($_POST) {
         $name = URL::title(Core::post('name'));
         $field = new Model_Field();
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE);
             if ($field->create($name, Core::post('type'), Core::post('values'), Core::post('categories'), $options)) {
                 Cache::instance()->delete_all();
                 Theme::delete_minified();
                 Alert::set(Alert::SUCCESS, __('Field created ' . $name));
                 Request::current()->redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
             } else {
                 Alert::set(Alert::ERROR, __('Field already exists ' . $name));
             }
         } catch (Exception $e) {
             throw new HTTP_Exception_500();
         }
     }
     $this->template->content = View::factory('oc-panel/pages/fields/new', array('categories' => $categories));
 }
Esempio n. 8
0
 public function set_values(array $data)
 {
     if (!Valid::url($data['next_url'])) {
         $data['next_url'] = NULL;
     }
     $data['fields'] = array();
     if (!empty($data['field']) and is_array($data['field'])) {
         foreach ($data['field'] as $key => $values) {
             foreach ($values as $index => $value) {
                 if ($index == 0) {
                     continue;
                 }
                 if ($key == 'source') {
                     $value = URL::title($value, '_');
                 }
                 $data['fields'][$index][$key] = $value;
             }
         }
         $data['field'] = NULL;
     }
     $email_type_fields = array();
     foreach ($data['fields'] as $field) {
         $email_type_fields['key'][] = $field['id'];
         $email_type_fields['value'][] = !empty($field['name']) ? $field['name'] : Inflector::humanize($field['id']);
     }
     $this->create_email_type($email_type_fields);
     return parent::set_values($data);
 }
Esempio n. 9
0
 public function action_new()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New field')));
     $this->template->title = __('New Custom Field for Advertisement');
     //find all, for populating form select fields
     $categories = Model_Category::get_as_array();
     $order_categories = Model_Category::get_multidimensional();
     if ($_POST) {
         if (count(Model_Field::get_all()) > 65) {
             Alert::set(Alert::ERROR, __('You have reached the maximum number of custom fields allowed.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
         }
         $name = URL::title(Core::post('name'));
         $field = new Model_Field();
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE, 'show_listing' => Core::post('show_listing') == 'on' ? TRUE : FALSE);
             if ($field->create($name, Core::post('type'), Core::post('values'), Core::post('categories'), $options)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s created'), $name));
             } else {
                 Alert::set(Alert::WARNING, sprintf(__('Field %s already exists'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
     }
     $this->template->content = View::factory('oc-panel/pages/fields/new', array('categories' => $categories, 'order_categories' => $order_categories));
 }
Esempio n. 10
0
 public static function slug($string, $replacement = '-')
 {
     $slug = UTF8::trim(UTF8::strtolower($string));
     $map = array('/ä/' => 'ae', '/ö/' => 'oe', '/ü/' => 'ue', '/щ/' => 'sch', '/ш/' => 'sh', '/ч/' => 'ch', '/ц/' => 'c', '/ю/' => 'yu', '/я/' => 'ya', '/ж/' => 'zh', '/а/' => 'a', '/б/' => 'b', '/в/' => 'v', '/г|ґ/' => 'g', '/д/' => 'd', '/е/' => 'e', '/ё/' => 'yo', '/з/' => 'z', '/и|і/' => 'i', '/й/' => 'y', '/к/' => 'k', '/л/' => 'l', '/м/' => 'm', '/н/' => 'n', '/о/' => 'o', '/п/' => 'p', '/р/' => 'r', '/с/' => 's', '/т/' => 't', '/у/' => 'u', '/ф/' => 'f', '/х/' => 'h', '/ы/' => 'y', '/э/' => 'e', '/є/' => 'ye', '/ї/' => 'yi', '/º|°/' => 0, '/¹/' => 1, '/²/' => 2, '/³/' => 3, '/à|á|å|â|ã|ä|ą|ă|ā|ª/' => 'a', '/@/' => 'at', '/æ/' => 'ae', '/ḃ/' => 'b', '/č|ç|¢|ć|ċ|ĉ|©/' => 'c', '/ď|ḋ|đ/' => 'd', '/€/' => 'euro', '/è|é|ê|ě|ẽ|ë|ę|ē|ė|ĕ/' => 'e', '/ƒ|ḟ/' => 'f', '/ģ|ğ|ĝ|ġ/' => 'g', '/ĥ|ħ/' => 'h', '/Ì|Í|Î|Ï/' => 'I', '/ì|í|î|ï|ĩ|ī|į|ı/' => 'i', '/ĵ/' => 'j', '/ķ/' => 'k', '/ł|ľ|ĺ|ļ/' => 'l', '/Ł/' => 'L', '/ṁ/' => 'm', '/ñ|ń|ņ|ň/' => 'n', '/ò|ó|ô|ø|õ|ö|ō|ð|ơ|ő/' => 'o', '/œ/' => 'oe', '/ṗ/' => 'p', '/ř|ŗ|ŕ|®/' => 'r', '/š|ś|ṡ|ş|ș/' => 's', '/ť|ț|ŧ|ţ|ṫ/' => 't', '/þ/' => 'th', '/ß/' => 'ss', '/™/' => 'tm', '/ù|ú|ů|û|ü|ū|ũ|ű|ŭ|ư|ų|µ/' => 'u', '/ẃ|ẅ|ẁ|ŵ/' => 'w', '/×/' => 'x', '/ÿ|ý|ỳ|ŷ|¥/' => 'y', '/Ž|Ż|Ź/' => 'Z', '/ž|ż|ź/' => 'z', '/\\s+/' => $replacement);
     $slug = preg_replace(array_keys($map), array_values($map), $slug);
     return URL::title($slug, $replacement);
 }
Esempio n. 11
0
 public function action_create()
 {
     if (Auth::is_admin_signed_in() === true) {
         $view = View::factory('acp/categories/create');
         $categories = new Model_Category();
         if ($this->request->method() === Request::POST) {
             $name = $this->request->post('name');
             $slug = $this->request->post('slug');
             $token = $this->request->param('id');
             if (!Security::check($token)) {
                 $this->request->redirect('acp/categories/create');
             }
             if (empty($slug)) {
                 $slug = URL::title($name, '_');
             }
             if (empty($name) && empty($slug)) {
                 $this->request->redirect('acp/categories/create');
             }
             $categories = new Model_Category();
             $create_category = $categories->create_category($name, $slug);
             if (!$create_category) {
                 $this->request->redirect('acp/categories/create');
             }
             $this->request->redirect('acp/categories');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }
Esempio n. 12
0
 public function set_inject_key($key)
 {
     if (empty($key)) {
         $this->inject_key = 'ids';
         return;
     }
     $this->inject_key = URL::title($key, '_');
 }
Esempio n. 13
0
 /**
  * 
  * @param string $part
  * @param boolean $inherit
  * @param integer $cache_lifetime
  */
 public function content($part = 'body', $inherit = FALSE, $cache_lifetime = NULL, array $tags = array())
 {
     $method = 'content_' . URL::title($part, '_');
     if (method_exists($this, $method)) {
         return $this->{$method}($cache_lifetime, $tags);
     }
     return parent::content($part, $inherit, $cache_lifetime, $tags);
 }
Esempio n. 14
0
 /**
  * Load a behavior and return it
  *
  * @param behavior_id string  The Behavior plugin folder name
  *
  * @return string   class name of the page
  */
 public static function load_page($behavior_id)
 {
     $behavior_page_class = 'Model_Page_Behavior_' . URL::title($behavior_id, '');
     if (class_exists($behavior_page_class)) {
         return $behavior_page_class;
     } else {
         return 'Model_Page_Behavior';
     }
 }
Esempio n. 15
0
 public function tabs()
 {
     $tabs = array();
     foreach ($this->tabs as $tab) {
         $tabs[] = array('name' => $tab->name, 'machine-name' => URL::title($tab->name), 'content' => $tab->render(), 'active' => FALSE);
     }
     isset($tabs[0]) and $tabs[0]['active'] = TRUE;
     return $tabs;
 }
Esempio n. 16
0
 /**
  * Slugifies titles
  * @param String String to slugify
  * @return String Slugified string
  */
 public static function slugify($slug)
 {
     $slug = mb_strtolower($slug);
     $slug = trim($slug);
     $slug = str_replace(array(' og ', ' at ', ' den ', ' det ', ' der ', ' som '), ' ', $slug);
     $slug = str_replace(array('æ', 'ø', 'å'), array('ae', 'o', 'aa'), $slug);
     $slug = str_replace(array('/', '\\', '_', '&'), '-', $slug);
     return URL::title($slug, '-', true);
 }
Esempio n. 17
0
 public static function select($name, array $options = NULL, $selected = NULL, array $attributes = NULL)
 {
     if (static::$model) {
         if (isset(static::$model->table_columns()[$name])) {
             $selected = static::$model->{$name};
             $attributes['id'] = static::$model_name . '_' . URL::title($name);
             $name = static::$model_name . '[' . $name . ']';
         }
     }
     return parent::select($name, $options, $selected, $attributes);
 }
Esempio n. 18
0
 /**
  * CRUD controller: CREATE
  */
 public function action_create()
 {
     $this->auto_render = FALSE;
     $this->template = View::factory('js');
     if (!isset($_FILES['image'])) {
         $this->template->content = json_encode('KO');
         return;
     }
     $image = $_FILES['image'];
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
             return;
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
         return;
     } elseif ($image != NULL) {
         // saving/uploading img file to dir.
         $path = 'images/cms/';
         $root = DOCROOT . $path;
         //root folder
         $image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
         $image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
         $image_name = time() . '.' . $image_name;
         // if folder does not exist, try to make it
         if (!file_exists($root) and !@mkdir($root, 0775, true)) {
             // mkdir not successful ?
             $this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
             return;
             // exit function
         }
         // save file to root folder, file, name, dir
         if ($file = Upload::save($image, $image_name, $root)) {
             // put image to Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
             }
             $this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
             return;
         } else {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
     }
 }
Esempio n. 19
0
 /**
  * Generate new reflink code
  *
  * @param   Model_User  $user
  * @param   integer		$type	reflink type
  * @param   string		$data	string stored to reflink in database
  * @return  string
  */
 public function generate(Model_User $user, $type, $data = NULL)
 {
     if (!$user->loaded()) {
         throw new Reflink_Exception(' User not loaded ');
     }
     $type = URL::title($type, '_');
     $reflink = $this->reset(FALSE)->where('user_id', '=', $user->id)->where('type', '=', $type)->where('created', '>', DB::expr('CURDATE() - INTERVAL 1 HOUR'))->find();
     if (!$reflink->loaded()) {
         $values = array('user_id' => (int) $user->id, 'code' => uniqid(TRUE) . sha1(microtime()), 'type' => $type, 'data' => $data);
         $reflink = ORM::factory('user_reflink')->values($values, array_keys($values))->create();
     } else {
         $reflink->set('data', $data)->update();
     }
     return $reflink->code;
 }
Esempio n. 20
0
 public function __construct()
 {
     parent::__construct();
     if (Kohana::$environment == Kohana::DEVELOPMENT) {
         if (!$this->check_db_structure()) {
             $this->create_db_structure();
             $this->insert_initial_data();
         }
     }
     // Add image files that does not exist in database
     $tracked_images = $this->get_images(NULL, array(), TRUE);
     $cwd = getcwd();
     chdir(Kohana::$config->load('user_content.dir') . '/images');
     $actual_images = glob('*.jpg');
     chdir($cwd);
     foreach (array_diff($actual_images, $tracked_images) as $non_tracked_image) {
         $pathinfo = pathinfo($non_tracked_image);
         if ($pathinfo['filename'] != URL::title($pathinfo['filename'])) {
             // We need to rename the image so it fits the URL
             $new_filename = URL::title($pathinfo['filename']);
             while (!Content_Image::image_name_available($new_filename)) {
                 $new_filename = URL::title($pathinfo['filename']) . '_' . $counter . '.jpg';
                 $counter++;
             }
             copy(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image, Kohana::$config->load('user_content.dir') . '/images/' . $new_filename . '.jpg');
             @unlink(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image);
             $non_tracked_image = $new_filename . '.jpg';
         }
         if (@($gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image))) {
             $gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image);
             $width = imagesx($gd_img_object);
             $height = imagesy($gd_img_object);
             $this->new_image($non_tracked_image, array('width' => $width, 'height' => $height));
         } else {
             // This jpg file is not a valid jpg image
             $path_parts = pathinfo($non_tracked_image);
             $new_filename = $path_parts['filename'] . '.broken_jpg';
             while (file_exists(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename)) {
                 if (!isset($counter)) {
                     $counter = 1;
                 }
                 $new_filename = $path_parts['filename'] . '_' . $counter . '.broken_jpg';
                 $counter++;
             }
             @rename(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image, Kohana::$config->load('user_content.dir') . '/images/' . $new_filename);
         }
     }
 }
 public static function getSlug($title, $counter = 0)
 {
     if ((bool) $counter) {
         $generatedSlug = URL::title($title . ' ' . $counter);
     } else {
         $generatedSlug = URL::title($title);
     }
     $game = ORM::factory('Game')->where('slug', '=', $generatedSlug)->find();
     // Means the slug isn't unique
     if ($game->loaded()) {
         $counter++;
         return self::getSlug($title, $counter);
     } else {
         return $generatedSlug;
     }
 }
Esempio n. 22
0
 /**
  * Override saving to perform additional functions on the river
  */
 public function save(Validation $validation = NULL)
 {
     // Do this for first time items only
     if ($this->loaded() === FALSE) {
         // Save the date this river was first added
         $this->river_date_add = date("Y-m-d H:i:s", time());
         // Set the expiry date
         $river_lifetime = Model_Setting::get_setting('river_lifetime');
         $expiry_date = strtotime(sprintf("+%s day", $river_lifetime), strtotime($this->river_date_add));
         $this->river_date_expiry = date("Y-m-d H:i:s", $expiry_date);
     }
     // Set river_name_url to the sanitized version of river_name sanitized
     $this->river_name_url = URL::title($this->river_name);
     $river = parent::save();
     // Swiftriver Plugin Hook -- execute after saving a river
     Swiftriver_Event::run('swiftriver.river.save', $river);
     return $river;
 }
Esempio n. 23
0
 /**
  * 
  * @param array $data
  */
 public function set_values(array $data)
 {
     if (empty($data['ds_id']) or !Datasource_Data_Manager::exists($data['ds_id'])) {
         $data['ds_id'] = 0;
     }
     $this->doc_fields = array();
     parent::set_values($data);
     $this->auto_publish = (bool) Arr::get($data, 'auto_publish');
     $this->disable_update = (bool) Arr::get($data, 'disable_update');
     $this->data_source_prefix = URL::title(Arr::get($data, 'data_source_prefix'), '_');
     if ($this->ds_id > 0) {
         $email_type_fields = array('key' => array('header', 'meta_title', 'meta_keywords', 'meta_description'), 'value' => array(__('Header'), __('Meta title'), __('Meta keywords'), __('Meta description')));
         $ds_fields = DataSource_Hybrid_Field_Factory::get_section_fields($this->ds_id);
         foreach ($ds_fields as $field) {
             $email_type_fields['key'][] = $field->name;
             $email_type_fields['value'][] = $field->header;
         }
         $this->create_email_type($email_type_fields);
     }
     return $this;
 }
Esempio n. 24
0
 public static function get_categories_for_xml()
 {
     $categories = array();
     $galleries = array();
     $gallery_names = 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)) {
                     $category = '';
                     $contents = Content_Content::get_contents_by_tags(array('gallery' => $tag_value, 'type' => 'category'));
                     foreach ($contents as $content) {
                         $category = $content['content'];
                     }
                     if ($category != '') {
                         if (!in_array($category, $categories)) {
                             $categories[] = $category;
                         }
                     }
                 }
                 $gallery_names[] = $tag_value;
             }
         }
     }
     // Fetch sort flags
     foreach ($categories as $nr => $category) {
         $categories[$category] = 0;
         $contents = Content_Content::get_contents_by_tags(array('category' => $category, 'type' => 'sort'));
         foreach ($contents as $content) {
             $categories[$category] = $content['content'];
         }
         unset($categories[$nr]);
     }
     // Organize for XML
     foreach ($categories as $category => $sort) {
         $categories[] = array('name' => $category, 'URI' => URL::title($category, '-', TRUE), 'sort' => $sort);
         unset($categories[$category]);
     }
     return $categories;
 }
Esempio n. 25
0
 public function action_new()
 {
     if ($this->request->method() == 'POST') {
         $oTrabajo = ORM::factory('Trabajo');
         $oTrabajo->values($this->request->post());
         $oTrabajo->tra_slug = $this->request->post('cgt_codigo') . '-' . URL::title($this->request->post('tra_nombre'));
         $fecha = date('Ymd', strtotime($this->request->post('tra_fecha_limite')));
         $fecha_actual = date('Ymd');
         $oTrabajo->tra_fecha_limite = date('Ymd', strtotime($this->request->post('tra_fecha_limite')));
         $oTrabajo->tra_codigo = Model_Trabajo::newCodigo();
         $oTrabajo->tra_fecha_registro = date('YmdHis');
         if ($this->request->post('tab_codigo') == 15) {
             $oTrabajo->tra_cantidad_alum = 1;
         }
         $oTrabajo->save();
         $this->redirect('/trabajo');
     }
     $aCurso = Model_Curso::getCursosUsuario($this->oUser->usuario->usu_usuario);
     $aTipo = Model_Tabladetabla::getTabla('TRABAJO');
     $view = View::factory('trabajo/new')->set('aCurso', $aCurso)->set('aTipo', $aTipo);
     $this->template->content = $view;
 }
Esempio n. 26
0
 public function action_add()
 {
     $this->template->title = 'Add Project';
     $this->template->left = array('text' => 'Projects', 'target' => 'project/');
     if ($_POST) {
         if (empty($_POST['name'])) {
             Message::error('Projects must have a name!');
             Request::instance()->redirect('project/');
             return;
         }
         $project = ORM::factory('project');
         $project->name = $_POST['name'];
         $project->user_id = Auth::instance()->get_user()->id;
         $project->slug = URL::title($_POST['name']);
         $project->save();
         if ($project->saved()) {
             Message::success('Created new project, ' . HTML::chars($project->name));
             Request::instance()->redirect('project/view/' . $project->id);
         } else {
             Message::error('Could not create project.');
         }
     }
 }
Esempio n. 27
0
 /**
  * return the title formatted for the URL
  *
  * @param  string $title
  * 
  */
 public function gen_seotitle($seotitle)
 {
     //in case seotitle is really small or null
     if (strlen($seotitle) < 3) {
         $seotitle = $this->title;
     }
     $seotitle = URL::title($seotitle);
     //this are reserved pages names used in the routes.php
     $banned_names = array(URL::title(__('search')), URL::title(__('contact')), URL::title(__('maintenance')), URL::title(__('publish new')), URL::title(__('map')));
     //same name as a route..shit!
     if (in_array($seotitle, $banned_names)) {
         $seotitle = URL::title(__('page')) . '-' . $seotitle;
     }
     if ($seotitle != $this->seotitle) {
         $cat = new self();
         //find a user same seotitle
         $s = $cat->where('seotitle', '=', $seotitle)->limit(1)->find();
         //found, increment the last digit of the seotitle
         if ($s->loaded()) {
             $cont = 2;
             $loop = TRUE;
             while ($loop) {
                 $attempt = $seotitle . '-' . $cont;
                 $cat = new self();
                 unset($s);
                 $s = $cat->where('seotitle', '=', $attempt)->limit(1)->find();
                 if (!$s->loaded()) {
                     $loop = FALSE;
                     $seotitle = $attempt;
                 } else {
                     $cont++;
                 }
             }
         }
     }
     return $seotitle;
 }
Esempio n. 28
0
 public function action_edit_page()
 {
     $id = $this->request->param('options');
     $content_page = new Content_Page($id);
     if ($content_page->get_page_id()) {
         $this->xml_content_page = $this->xml_content->appendChild($this->dom->createElement('page'));
         // Get all tags associated with pages and images
         $this->xml_content_tags = $this->xml_content->appendChild($this->dom->createElement('tags'));
         $tags = array();
         foreach (Content_Page::get_tags() as $tag) {
             $tags[] = $tag;
         }
         foreach (Content_Image::get_tags() as $tag) {
             foreach ($tags as $tag_to_check) {
                 if ($tag_to_check['name'] == $tag['name']) {
                     break 2;
                 }
             }
             $tags[] = $tag;
         }
         foreach ($tags as $tag) {
             $tag_node = $this->xml_content_tags->appendChild($this->dom->createElement('tag', $tag['name']));
             $tag_node->setAttribute('id', $tag['id']);
         }
         if (count($_POST) && isset($_POST['URI']) && isset($_POST['name'])) {
             if ($_POST['URI'] == '') {
                 $_POST['URI'] = $_POST['name'];
             }
             $_POST['URI'] = URL::title($_POST['URI'], '-', TRUE);
             $post = new Validation($_POST);
             $post->filter('trim');
             $post->rule('Valid::not_empty', 'name');
             if ($post->validate()) {
                 $post_values = $post->as_array();
                 $current_page_data = $content_page->get_page_data();
                 if ($post_values['name'] != $current_page_data['name'] && !Content_Page::page_name_available($post_values['name'])) {
                     $post->add_error('name', 'Content_Page::page_name_available');
                 }
                 if ($post_values['URI'] != $current_page_data['URI'] && !Content_Page::page_URI_available($post_values['URI'])) {
                     $post->add_error('URI', 'Content_Page::page_URI_available');
                 }
             }
             // Retry
             if ($post->validate()) {
                 $tags = array();
                 foreach ($post_values['template_position'] as $nr => $template_position) {
                     if ($post_values['tag_id'][$nr] > 0) {
                         if (!isset($tags[$template_position])) {
                             $tags[$template_position] = array();
                         }
                         $tags[$template_position][] = $post_values['tag_id'][$nr];
                     }
                 }
                 $content_page->update_page_data($post_values['name'], $post_values['URI'], $tags);
                 $this->add_message('Page "' . $post_values['name'] . '" updated');
                 $page_data = $content_page->get_page_data();
                 unset($page_data['tag_ids']);
                 $this->set_formdata($page_data);
             } else {
                 $this->add_error('Fix errors and try again');
                 $this->add_form_errors($post->errors());
                 // Fix template position data
                 $tmp_node = $this->xml_content->appendChild($this->dom->createElement('tmp'));
                 foreach ($post_values['template_position'] as $nr => $template_position) {
                     $template_field_node = $tmp_node->appendChild($this->dom->createElement('template_field'));
                     $template_field_node->setAttribute('id', $template_position);
                     if ($post_values['tag_id'][$nr] > 0) {
                         $tag_node = $template_field_node->appendChild($this->dom->createElement('tag'));
                         $tag_node->setAttribute('id', $post_values['tag_id'][$nr]);
                     }
                 }
                 unset($post_values['template_position'], $post_values['tag_id']);
                 $this->set_formdata($post_values);
             }
         } else {
             $page_data = $content_page->get_page_data();
             unset($page_data['tag_ids']);
             $this->set_formdata($page_data);
         }
         /**
          * Put the page data to the XML
          *
          */
         $page_data = $content_page->get_page_data();
         $page_data['template_fields'] = array();
         foreach ($page_data['tag_ids'] as $template_field_id => $tag_ids) {
             $page_data['template_fields'][$template_field_id . 'template_field'] = array('@id' => $template_field_id);
             foreach ($tag_ids as $tag_id) {
                 $page_data['template_fields'][$template_field_id . 'template_field'][$tag_id . 'tag'] = array('@id' => $tag_id);
             }
         }
         // Unset this, or it will cludge our XML
         unset($page_data['tag_ids']);
         // Set the page data to the page node
         xml::to_XML($page_data, $this->xml_content_page, NULL, 'id');
     } else {
         $this->redirect();
     }
 }
Esempio n. 29
0
    ?>
 - <?php 
    echo Model_Location::current()->name;
    ?>
"  href="<?php 
    echo Route::url('rss', array('category' => Model_Category::current()->seoname, 'location' => Model_Location::current()->seoname));
    ?>
" />
<?php 
} elseif (Model_Location::current()->loaded()) {
    ?>
<link rel="alternate" type="application/atom+xml"  title="RSS <?php 
    echo HTML::chars(Core::config('general.site_name') . ' - ' . Model_Location::current()->name);
    ?>
"  href="<?php 
    echo Route::url('rss', array('category' => URL::title(__('all')), 'location' => Model_Location::current()->seoname));
    ?>
" />
<?php 
} elseif (Model_Category::current()->loaded()) {
    ?>
<link rel="alternate" type="application/atom+xml"  title="RSS <?php 
    echo HTML::chars(Core::config('general.site_name') . ' - ' . Model_Category::current()->name);
    ?>
"  href="<?php 
    echo Route::url('rss', array('category' => Model_Category::current()->seoname));
    ?>
" />
<?php 
}
?>
Esempio n. 30
0
 /**
  * Tests URL::title()
  *
  * @test
  * @dataProvider provider_title
  * @param string $title        Input to convert
  * @param string $separator    Seperate to replace invalid characters with
  * @param string $expected     Expected result
  */
 public function test_title($expected, $title, $separator, $ascii_only = FALSE)
 {
     $this->assertSame($expected, URL::title($title, $separator, $ascii_only));
 }