Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: php

php:
- 5.3
- 5.4
- 5.5

- 5.6
- 7.0
env:
global:
- PLUGIN_NAME=I18n
Expand All @@ -16,16 +15,15 @@ env:

matrix:
include:
- php: 5.3
- php: 5.5
env:
- CAKE_VERSION=2.6
- php: 5.4
- CAKE_VERSION=2.7
- php: 5.6
env:
- CAKE_VERSION=2.6
- php: 5.5
- CAKE_VERSION=2.7
- php: 7.0
env:
- CAKE_VERSION=2.6

- CAKE_VERSION=2.9
before_script:
- git clone https://github.com/steinkel/travis.git --depth 1 ../travis
- ../travis/before_script.sh
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Contributing
============

This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugins). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](http://cakedc.com/plugins) for detailed instructions.
This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](http://cakedc.com/contribution-guidelines) for detailed instructions.
2 changes: 2 additions & 0 deletions Controller/I18nAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
App::uses('AppController', 'Controller');

App::uses('AppController', 'Controller');

/**
* I18n AppController
*
Expand Down
5 changes: 3 additions & 2 deletions Controller/TranslationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,17 @@ protected function _pluginLoaded($plugin, $exception = true) {
* @access public
*/
public function admin_index() {
$conditions = array();
if ($this->_pluginLoaded('Search', false)) {
$this->Prg->commonProcess();
$conditions = $this->Translation->parseCriteria($this->passedArgs);
} else {
$conditions= array();
}

$this->Paginator->settings = array(
'search',
'conditions' => $conditions
);

$this->set('translations', $this->Paginator->paginate());
}

Expand Down
4 changes: 2 additions & 2 deletions Lib/Routing/Route/I18nRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ protected function _shouldStripDefaultLanguageOnMatch() {
public function getDefaultLanguage() {
$lang = Configure::read('Config.languageOverride');
if (empty($lang)) {
$lang = Configure::read('Config.language');
return $lang;
return Configure::read('Config.language');
}

return $lang;
}

Expand Down
41 changes: 21 additions & 20 deletions Lib/Routing/Route/SluggableRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function match($url) {
public function slug($slug) {
$str = $slug['_field'];
if ($slug['_count'] > 1 || (isset($this->options['prependPk']) && $this->options['prependPk'])) {
$str = $slug['_pk'].' '.$str;
$str = $slug['_pk'] . ' ' . $str;
}
return $this->_slug($str);
}
Expand Down Expand Up @@ -129,10 +129,10 @@ protected function _slug($str, $replacement = '-') {
*/
public function getSlugs($modelName, $field = null) {
$cacheConfig = $this->_initSluggerCache();
if (!isset($this->{$modelName.'_slugs'})) {
$this->{$modelName.'_slugs'} = Cache::read($modelName.'_slugs', $cacheConfig);
if (!isset($this->{$modelName . '_slugs'})) {
$this->{$modelName . '_slugs'} = Cache::read($modelName.'_slugs', $cacheConfig);
}
if (empty($this->{$modelName.'_slugs'})) {
if (empty($this->{$modelName . '_slugs'})) {
$Model = ClassRegistry::init($modelName);
if ($Model === false) {
return false;
Expand All @@ -142,21 +142,21 @@ public function getSlugs($modelName, $field = null) {
}
$slugs = $Model->find('all', array(
'fields' => array(
$Model->name.'.'.$Model->primaryKey,
$Model->name.'.'.$field,
$Model->name . '.' . $Model->primaryKey,
$Model->name . '.' . $field,
),
'recursive' => -1
));
$counts = $Model->find('all', array(
'fields' => array(
'LOWER(TRIM('.$Model->name.'.'.$field.')) AS '.$field,
'LOWER(TRIM(' . $Model->name . '.' . $field . ')) AS ' . $field,
'COUNT(*) AS count'
),
'group' => array(
$field
)
));
$counts = Set::combine($counts, '{n}.0.'.$field, '{n}.0.count');
$counts = Set::combine($counts, '{n}.0.' . $field, '{n}.0.count');
$listedSlugs = array();
foreach ($slugs as $pk => $fields) {
$values = array(
Expand All @@ -166,11 +166,11 @@ public function getSlugs($modelName, $field = null) {
);
$listedSlugs[$fields[$Model->name][$Model->primaryKey]] = $this->slug($values);
}
Cache::write($modelName.'_slugs', $listedSlugs, $cacheConfig);
$this->{$modelName.'_slugs'} = $listedSlugs;
Cache::write($modelName . '_slugs', $listedSlugs, $cacheConfig);
$this->{$modelName . '_slugs'} = $listedSlugs;
}
return $this->{$modelName.'_slugs'};

return $this->{$modelName . '_slugs'};
}

/**
Expand All @@ -184,21 +184,21 @@ public function invalidateCache($modelName, $id = null) {
$cacheConfig = $this->_initSluggerCache();

if (is_null($id)) {
$result = Cache::delete($modelName.'_slugs', $cacheConfig);
unset($this->{$modelName.'_slugs'});
$result = Cache::delete($modelName . '_slugs', $cacheConfig);
unset($this->{$modelName . '_slugs'});
} else {
$slugs = Cache::read($modelName.'_slugs', $cacheConfig);
$slugs = Cache::read($modelName . '_slugs', $cacheConfig);
if ($slugs === false) {
$result = false;
} else {
$slugs[$id] = $this->generateSlug($modelName, $id);
if ($slugs[$id] === false) {
unset($slugs[$id]);
}
if (isset($this->{$modelName.'_slugs'}) && $slugs[$id] !== false) {
$this->{$modelName.'_slugs'}[$id] = $slugs[$id];
if (isset($this->{$modelName . '_slugs'}) && $slugs[$id] !== false) {
$this->{$modelName . '_slugs'}[$id] = $slugs[$id];
}
$result = Cache::write($modelName.'_slugs', $slugs, $cacheConfig);
$result = Cache::write($modelName . '_slugs', $slugs, $cacheConfig);
}
}

Expand Down Expand Up @@ -230,11 +230,11 @@ public function generateSlug($modelName, $id) {
$slugField = $Model->displayField;
}
$text = $Model->field($slugField, array(
$Model->name.'.'.$Model->primaryKey => $id
$Model->name . '.' . $Model->primaryKey => $id
));
if ($text !== false) {
$count = $Model->find('count', array(
'conditions' => array($Model->name.'.'.$slugField => $text)
'conditions' => array($Model->name . '.' . $slugField => $text)
));
$values = array('_field' => $text, '_count' => $count, '_pk' => $id);
$slug = $this->slug($values);
Expand All @@ -257,6 +257,7 @@ protected function _initSluggerCache() {
'duration' => '+1 days',
'prefix' => 'slugger_'
));

return 'Slugger';
}
}
Expand Down
1 change: 1 addition & 0 deletions Model/Behavior/I18nableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ public function beforeSave(Model $Model, $options = array()) {
$Model->set(array($settings['languageField'] => $language));
}
}
return true;
}
}
98 changes: 59 additions & 39 deletions Model/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,29 @@ class Translation extends I18nAppModel {
*/
public $validate = array(
'locale' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a Locale')),
'rule' => array('notBlank'),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a Locale'
),
'model' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a Model')),
'rule' => array('notBlank'),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a Model'
),
'foreign_key' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a Foreign Key')),
'rule' => array('notBlank'),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a Foreign Key'
),
'field' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a Field')),
'rule' => array('notBlank'),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a Field'
),
);

/**
Expand Down Expand Up @@ -106,12 +122,11 @@ public function add($data = null) {
$this->create();
$result = $this->save($data);
if ($result !== false) {
$this->data = array_merge($data, $result);
return true;
$this->data = Hash::merge($data, $result);
return $return;
} else {
throw new OutOfBoundsException(__('Could not save the translation, please check your inputs.', true));
}
return $return;
}
}

Expand All @@ -128,7 +143,8 @@ public function edit($id = null, $data = null) {
$translation = $this->find('first', array(
'conditions' => array(
"{$this->alias}.{$this->primaryKey}" => $id,
)));
)
));

if (empty($translation)) {
throw new OutOfBoundsException(__('Invalid Translation', true));
Expand All @@ -141,12 +157,12 @@ public function edit($id = null, $data = null) {
if ($result) {
$this->data = $result;
return true;
} else {
return $data;
}
} else {
return $translation;
return $data;
}

return $translation;
}

/**
Expand Down Expand Up @@ -175,28 +191,29 @@ public function edit_multi($model, $foreignKey, $data = null) {
// $this->set($translation);

if (!empty($data[$this->alias])) {
foreach ($data[$this->alias] as $locale => $fields) {
foreach ($fields as $field => $_data) {
if (!empty($_data['id'])) {
$record = $this->read(null, $_data['id']);
$record[$this->alias]['content'] = $_data['content'];
$this->save($record);
} else {
$record = array('Translation' => array(
'model' => $model,
'foreign_key' => $foreignKey,
'locale' => $locale,
'field' => $field,
'content' => $_data['content']));
$this->create($record);
$this->save($record);
}
foreach ($data[$this->alias] as $locale => $fields) {
if (!empty($fields['id'])) {
$record = $this->read(null, $_data['id']);
$record[$this->alias]['content'] = $_data['content'];
$this->set($record);
$this->save($record);
} else {
$record = array('Translation' => array(
'model' => $model,
'foreign_key' => $foreignKey,
'locale' => $fields['locale'],
'field' => $fields['field'],
'content' => $fields['content']
));
$this->create($record);
$this->save($record);
}
}

return true;
} else {
return $translations;
}

return $translations;
}

/**
Expand All @@ -209,7 +226,9 @@ public function edit_multi($model, $foreignKey, $data = null) {
public function view($id = null) {
$translation = $this->find('first', array(
'conditions' => array(
"{$this->alias}.{$this->primaryKey}" => $id)));
"{$this->alias}.{$this->primaryKey}" => $id
)
));

if (empty($translation)) {
throw new OutOfBoundsException(__('Invalid Translation', true));
Expand All @@ -225,13 +244,14 @@ public function view($id = null) {
* @param array $data, controller post data usually $this->data
* @return boolean True on success
* @throws OutOfBoundsException If the element does not exists
* @throws Exception If the confirmation was not send
*/
public function validateAndDelete($id = null, $data = array()) {
$translation = $this->find('first', array(
'conditions' => array(
"{$this->alias}.{$this->primaryKey}" => $id,
))
);
)
));

if (empty($translation)) {
throw new OutOfBoundsException(__('Invalid Translation', true));
Expand All @@ -242,8 +262,9 @@ public function validateAndDelete($id = null, $data = array()) {
$data['Translation']['id'] = $id;
$tmp = $this->validate;
$this->validate = array(
'id' => array('rule' => 'notEmpty'),
'confirm' => array('rule' => '[1]'));
'id' => array('rule' => 'notBlank'),
'confirm' => array('rule' => '[1]')
);

$this->set($data);
if ($this->validates()) {
Expand All @@ -259,14 +280,13 @@ public function validateAndDelete($id = null, $data = array()) {
/**
* Perform search request
*
* @param string $state
* @param array $query
* @param array $results
* @param string $state query state
* @param array $query array
* @param array $results results
* @return array
*/
protected function _findSearch($state, $query, $results = array()) {
if ($state == 'before') {
//$query = Set::merge($defaults, $query);
if (!empty($query['operation']) && $query['operation'] === 'count') {
unset($query['limit']);
$query = $this->_findCount('before', $query, $results);
Expand Down
Loading