summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LibertyTranslations.php81
-rw-r--r--admin/schema_inc.php7
-rw-r--r--bit_setup_inc.php19
-rw-r--r--templates/select_translations.tpl13
4 files changed, 100 insertions, 20 deletions
diff --git a/LibertyTranslations.php b/LibertyTranslations.php
index d2cb1da..5f8735c 100644
--- a/LibertyTranslations.php
+++ b/LibertyTranslations.php
@@ -1,5 +1,5 @@
<?php
-class LibertyTranslations extends BitBase {
+class LibertyTranslations extends LibertyBase {
function LibertyTranslations( $pContentId = NULL ) {
$this->mContentId = $pContentId;
LibertyBase::LibertyBase();
@@ -22,11 +22,61 @@ class LibertyTranslations extends BitBase {
}
return $ret;
}
+
+ function storeTranslation( $pParamHash ) {
+ if( $this->verify( $pParamHash ) ) {
+ $table = BIT_DB_PREFIX."i18n_content_trans_map";
+ if( !@BitBase::verifyId( $pParamHash['translation_store']['translation_id'] ) && is_array( $pParamHash['translation_store'] ) ) {
+ // using the from_id as translation_id
+ //$translationId = $this->mDb->GenID( 'i18n_content_trans_id_seq' );
+
+ // --- i can't work out why this isn't storing! driving me nuts ----
+ foreach( $pParamHash['translation_store'] as $store ) {
+ //vd($store);
+ $result = $this->mDb->associateInsert( $table, $store );
+ }
+ } else {
+ $result = $this->mDb->associateInsert( $table, $pParamHash['translation_store'] );
+ }
+ }
+ }
+
+ function verify( &$pParamHash ) {
+ $i = 0;
+ // we should make sure that we don't have an entry for this content_id / lang_code combo yet
+ if( !$this->mDb->getOne( "SELECT `content_id` FROM `".BIT_DB_PREFIX."liberty_content` WHERE `content_id`=? AND `lang_code`=?", array( $pParamHash['content_id'], $pParamHash['lang_code'] ) ) ) {
+ //return FALSE;
+ }
+
+ // make sure we don't have a translation_id for this content yet
+ if( @BitBase::verifyId( $pParamHash['from_id'] ) ) {
+ $pParamHash['translation_id'] = $this->mDb->getOne( "SELECT `translation_id` FROM `".BIT_DB_PREFIX."i18n_content_trans_map` WHERE `content_id`=?", array( $pParamHash['content_id'] ) );
+ }
+
+ // we have a from_id but no translation_id, this is a new entry in the translation map and we need both, the original and the new content_id entered
+ if( @BitBase::verifyId( $pParamHash['translation_id'] ) ) {
+ $pParamHash['translation_store']['translation_id'] = $pParamHash['translation_id'];
+ $pParamHash['translation_store']['content_id'] = $pParamHash['content_id'];
+ } elseif( @BitBase::verifyId( $pParamHash['from_id'] ) ) {
+ // we can simply use the from_id as the translation_id
+ $pParamHash['translation_store'][$i]['translation_id'] = $pParamHash['from_id'];
+ $pParamHash['translation_store'][$i]['content_id'] = $pParamHash['from_id'];
+ $i++;
+ $pParamHash['translation_store'][$i]['translation_id'] = $pParamHash['from_id'];
+ $pParamHash['translation_store'][$i]['content_id'] = $pParamHash['content_id'];
+ }
+ return( count( $this->mErrors ) == 0 );
+ }
+
+ function expunge() {
+ if( @BitBase::verifyId( $this->mContentId ) ) {
+ $result = $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."i18n_content_trans_map` WHERE `content_id`=?", $this->mContentId );
+ }
+ }
}
// ================== service functions ==================
-// we should force the preview stuff to preview the original code
function translation_content_edit( &$pObject, &$pParamHash ) {
global $gBitLanguage, $gBitSmarty, $gBitUser;
$trans = new LibertyTranslations( $pObject->mContentId );
@@ -42,10 +92,33 @@ function translation_content_edit( &$pObject, &$pParamHash ) {
}
$gBitSmarty->assign( 'translationsList', $translationsList );
$gBitSmarty->assign( 'translationId', $translationId );
+
+ if( @BitBase::verifyId( $_REQUEST['i18n']['from_id'] ) || @BitBase::verifyId( $_REQUEST['i18n']['translation_id'] ) ) {
+ if( @BitBase::verifyId( $_REQUEST['i18n']['from_id'] ) ) {
+ // load the content we're translating from
+ $transObject = $trans->getLibertyObject( $_REQUEST['i18n']['from_id'] );
+ $gBitSmarty->assign_by_ref( "translateFrom", $transObject );
+ }
+ }
}
// store the content
-function translation_content_store() {
- // we need a parameter on store that we can insert something in liberty_content.lang_code
+function translation_content_store( $pObject, $pParamHash ) {
+ // if we are creating this content and we have a from_id, we know that we're translating a page
+ // how do we check if this is the first install??? $pObject already contains stuff...
+ if( @BitBase::verifyId( $_REQUEST['i18n']['from_id'] ) ) {
+ $trans = new LibertyTranslations();
+ $storeHash = $_REQUEST['i18n'];
+ $storeHash['content_id'] = $pParamHash['content_id'];
+ if( !$trans->storeTranslation( $storeHash ) ) {
+ // error
+ }
+ }
+ die;
+}
+
+function translation_content_exunge( $pObject, $pParamHash ) {
+ $trans = new LibertyTranslations( $pObject->mContentId );
+ $trans->expunge();
}
?>
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index 3e7a14f..5776f3b 100644
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -52,9 +52,14 @@ $indices = array (
'i18n_version_src_idx' => array( 'table' => 'i18n_version_map', 'cols' => 'source_hash', 'opts' => NULL ),
'i18n_version_ver_idx' => array( 'table' => 'i18n_version_map', 'cols' => 'version', 'opts' => NULL ),
);
-
$gBitInstaller->registerSchemaIndexes( LANGUAGES_PKG_NAME, $indices );
+// ### Sequences
+$sequences = array (
+ 'i18n_content_trans_id_seq' => array( 'start' => 1 ),
+);
+$gBitInstaller->registerSchemaSequences( LIBERTY_PKG_NAME, $sequences );
+
$gBitInstaller->registerPackageInfo( LANGUAGES_PKG_NAME, array(
'description' => "This package allows you to translate your site into a different language.",
'license' => '<a href="http://www.gnu.org/licenses/licenses.html#LGPL">LGPL</a>',
diff --git a/bit_setup_inc.php b/bit_setup_inc.php
index c3d31b4..a373aa7 100644
--- a/bit_setup_inc.php
+++ b/bit_setup_inc.php
@@ -37,13 +37,14 @@ if( !empty( $_REQUEST['oe'] ) && !empty( $gBitLanguage->mLanguageList[$_REQUEST[
$gBitSmarty->assign('bitlanguage', $gBitLanguage->mLanguage);
-if (!empty($gLibertySystem) && $gBitSystem->isFeatureActive( 'i18n_content_translation' ) ) {
+if( !empty( $gLibertySystem ) && $gBitSystem->isFeatureActive( 'i18n_content_translation' ) ) {
require_once( LANGUAGES_PKG_PATH . 'LibertyTranslations.php' );
$gLibertySystem->registerService( LIBERTY_SERVICE_TRANSLATION, LANGUAGES_PKG_NAME, array(
//'content_display_function' => 'translation_content_display',
//'content_preview_function' => 'translation_content_edit',
'content_edit_function' => 'translation_content_edit',
'content_store_function' => 'translation_content_store',
+ 'content_expunge_function' => 'translation_content_exunge',
//'content_list_sql_function' => 'translation_content_list',
//'content_load_sql_function' => 'translation_content_load',
'content_edit_mini_tpl' => 'bitpackage:languages/select_translations.tpl',
@@ -51,18 +52,18 @@ if (!empty($gLibertySystem) && $gBitSystem->isFeatureActive( 'i18n_content_trans
) );
}
-if( !empty( $_POST['translate'] ) ) {
- if( is_numeric( $_POST['translate_content_id'] ) ) {
- $get = 'content_id='.$_POST['translate_content_id'];
+if( !empty( $_POST['i18n']['translate'] ) ) {
+ if( @BitBase::verifyId( $_POST['i18n']['to_id'] ) ) {
+ $get = 'i18n[to_id]='.$_POST['i18n']['to_id'];
} else {
- $get = 'lang_code='.$_POST['translate_content_id'];
+ $get = 'i18n[lang_code]='.$_POST['i18n']['to_id'];
}
- if( LibertyBase::verifyId( $_POST['translate_id'] ) ) {
- $get .= '&translate_group_id='.$_POST['translate_id'];
+ if( @BitBase::verifyId( $_POST['i18n']['translation_id'] ) ) {
+ $get .= '&i18n[translation_id]='.$_POST['i18n']['translation_id'];
} else {
- $get .= '&translate_from_id='.$_POST['content_id'];
+ $get .= '&i18n[from_id]='.$_POST['i18n']['from_id'];
}
- header( 'Location: '.$_SERVER['SCRIPT_URL'].'?'.$get );
+ header( 'Location: '.$_SERVER['PHP_SELF'].'?'.$get );
die;
}
?>
diff --git a/templates/select_translations.tpl b/templates/select_translations.tpl
index 05e7116..4ece604 100644
--- a/templates/select_translations.tpl
+++ b/templates/select_translations.tpl
@@ -1,16 +1,17 @@
{* don't show if this is the page creation *}
<div class="row">
- {formlabel label="Translations" for=""}
+ {formlabel label="Translations" for="to_id"}
{forminput}
- <input type="hidden" name="translation_id" value="{$translationId}" />
- <select name="translate_content_id">
+ <input type="hidden" name="i18n[translation_id]" value="{$translationId}" />
+ <input type="hidden" name="i18n[from_id]" value="{$smarty.request.i18n.from_id|default:$gContent->mContentId}" />
+ <select name="i18n[to_id]" id="to_id">
{foreach from=$translationsList key=langCode item=lang}
<option value="{$lang.content_id|default:$langCode}">{$lang.native_name}: &nbsp; {$lang.title|default:"&bull; {tr}Create New{/tr} &bull;"}</option>
{/foreach}
</select>
+ &nbsp; <label><input type="checkbox" name="i18n[google]" /> {tr}Attempt Google translation{/tr}</label>
<br />
- <label><input type="checkbox" name="translate_google" /> {tr}Attempt Google translation{/tr}</label><br/>
- <input type="submit" name="translate" value="{tr}Translate{/tr}" />
- {formhelp note="If you feel like translating this page into a different language, please select the correct languages above and hit <strong>translate</strong>."}
+ <input type="submit" name="i18n[translate]" value="{tr}Translate{/tr}" />
+ {formhelp note="If you feel like translating this page into a different language, please select the correct language above and hit <strong>Translate</strong>."}
{/forminput}
</div>