Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1051829
phrases_event_handler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jul 4, 5:05 AM
Size
2 KB
Mime Type
text/x-php
Expires
Sun, Jul 6, 5:05 AM (18 h, 42 m)
Engine
blob
Format
Raw Data
Handle
679136
Attached To
rINP In-Portal
phrases_event_handler.php
View Options
<?php
class
PhrasesEventHandler
extends
InpDBEventHandler
{
/**
* Forces new label in case if issued from get link
*
* @param kEvent $event
*/
function
OnNew
(&
$event
)
{
parent
::
OnNew
(
$event
);
$label
=
$this
->
Application
->
GetVar
(
'phrases_label'
);
$this
->
Application
->
setUnitOption
(
$event
->
Prefix
,
'AutoLoad'
,
false
);
$object
=&
$event
->
getObject
(
$label
?
Array
(
'live_table'
=>
true
)
:
Array
()
);
if
(
$label
)
{
$object
->
SetDBField
(
'Phrase'
,
$label
);
$object
->
SetDBField
(
'LanguageId'
,
$this
->
Application
->
GetVar
(
'm_lang'
)
);
$object
->
SetDBField
(
'PhraseType'
,
1
);
$primary_language
=
$this
->
Application
->
GetDefaultLanguageId
();
$live_table
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
);
$sql
=
'SELECT Translation FROM %s WHERE Phrase = %s'
;
$primary_value
=
$this
->
Conn
->
GetOne
(
sprintf
(
$sql
,
$live_table
,
$this
->
Conn
->
qstr
(
$label
)
)
);
$object
->
SetDBField
(
'PrimaryTranslation'
,
$primary_value
);
}
$last_module
=
$this
->
Application
->
GetVar
(
'last_module'
);
if
(
$last_module
)
$object
->
SetDBField
(
'Module'
,
$last_module
);
if
(
$event
->
Special
==
'export'
||
$event
->
Special
==
'import'
)
{
$object
->
SetDBField
(
'PhraseType'
,
'|0|1|2|'
);
$modules
=
$this
->
Conn
->
GetCol
(
'SELECT Name FROM '
.
TABLE_PREFIX
.
'Modules'
);
$object
->
SetDBField
(
'Module'
,
'|'
.
implode
(
'|'
,
$modules
).
'|'
);
}
}
/**
* Forces create to use live table
*
* @param kEvent $event
*/
function
OnBeforePhraseCreate
(&
$event
)
{
$edit_direct
=
$this
->
Application
->
GetVar
(
$event
->
Prefix
.
'_label'
);
if
(
$edit_direct
)
{
$this
->
Application
->
setUnitOption
(
$event
->
Prefix
,
'AutoLoad'
,
false
);
$object
=&
$event
->
getObject
();
if
(
$this
->
Application
->
GetVar
(
'm_lang'
)
!=
$this
->
Application
->
GetVar
(
'lang_id'
)
)
{
$object
->
SwitchToLive
();
}
}
}
/**
* Save phrase change date & ip translation was made from
*
* @param kEvent $event
*/
function
OnSetLastUpdated
(&
$event
)
{
$object
=&
$event
->
getObject
();
$prev_translation
=
$this
->
Conn
->
GetOne
(
'SELECT Translation FROM '
.
$object
->
TableName
.
' WHERE '
.
$object
->
IDField
.
' = '
.(
int
)
$object
->
GetId
()
);
if
(
$prev_translation
!=
$object
->
GetDBField
(
'Translation'
)
)
{
$ip_address
=
getenv
(
'HTTP_X_FORWARDED_FOR'
)
?
getenv
(
'HTTP_X_FORWARDED_FOR'
)
:
getenv
(
'REMOTE_ADDR'
);
$object
->
SetDBField
(
'LastChanged_date'
,
adodb_mktime
()
);
$object
->
SetDBField
(
'LastChanged_time'
,
adodb_mktime
()
);
$object
->
SetDBField
(
'LastChangeIP'
,
$ip_address
);
}
$cookie_path
=
$this
->
Application
->
IsAdmin
()
?
BASE_PATH
.
'/admin'
:
BASE_PATH
;
setcookie
(
'last_module'
,
$object
->
GetDBField
(
'Module'
),
$cookie_path
,
'.'
.
SERVER_NAME
);
}
}
?>
Event Timeline
Log In to Comment