User Tools

Site Tools


ru:plugins:tips

This is an old revision of the document!


Советы и рекомендации

Если вы разработчик плагинов – вам следует ознакомиться с новой системой обновлений, интегрированной в GetSimple 3.1. Начиная с этой версии, GetSimple уведомляет пользова-теля при появлении новой версии плагина для загрузки в секции сайта GS Extend. При разработке плагина для достижения его совместимости с новой системой необходимо следовать рекомендациям, изложенным в секции ВИКИ "Взаимодействие плагинов и секции Extend сайта get-simple.info"

Определение версии GetSimple

Определение версии GetSimple – не такая простая задача, так как единственная доступная функция return_site_ver(), выводящая на экран номер версии в GS 2.03 и возвращающая результат в версии 3.0b уже устарела (прим. переводчика – пометка о том, что данная функция устарела (??) в списке тэгов англоязычной Вики отсутствует). На самом деле, по заявлению разработчиков, return_site_ver() применяется до сих пор и не является устаревшей.

Самый простой способ определить, установлен ли плагин под GetSimple 2.03 или 3.0+:

$isV3 = function_exists('get_site_version');

Самый правильный способ определения версии – следующий (используйте его только внутри функций, чтобы не засорять глобальное пространство имен!):

include(GSADMININCPATH.'configuration.php');
$version = GSVERSION;

Обход отсутствия хука Page-Delete в 2.03

Для запуска функции вашего плагина myplugin_function при удалении страницы в GetSimple 2.03 и 3.0+ применяйте следующий код:

// GetSimple 3.0+
add_action('page-delete', 'myplugin_function'); 

// GetSimple 2.03
if (!function_exists('get_site_version') && basename($_SERVER['PHP_SELF']) == 'deletefile.php') {
  myplugin_function();
}

Success and Error Messages

This describes how to display messages in back-end plugin pages. Assume you have 3 variables, $isSuccess, $canUndo and $msg holding the message. To display the message for your plugin myplugin, add the following code to your plugin:

<?php 
  if (isset($msg)) {
    if ($canUndo) $msg .= ' <a href="load.php?id=myplugin&undo">' . i18n_r('UNDO') . '</a>' 
?>
<script type="text/javascript">
  $(function() {
    $('div.bodycontent').before('<div class="<?php echo $isSuccess ? 'updated' : 'error'; ?>" style="display:block;">'+
            <?php echo json_encode($msg); ?>+'</div>');
    $(".updated, .error").fadeOut(500).fadeIn(500);
  });
</script>
<?php 
  } 
?>

Displaying custom and localized Dates

The publication date in the page XML files is stored in an english text format, which can be converted to a UNIX timestamp with

$timestamp = strtotime($data->pubDate);

GetSimple itself uses the date function to display dates, which will work with other languages only when no weekday or month names are displayed, as these will always be in english.

To display a truly localized date, use:

$dateLocale = 'de_DE,de,ger,deu';      // or use $LANG or a setting in your plugin, 
                                       // for OS compatibility multiple locales should be possible
$dateFormat = "%A, %d.%m.%Y - %H:%M";  // should be a entry in the i18n language file of your plugin
                                       // for the format see PHP function strftime
$oldlocale = setLocale(LC_TIME, '0');  // save old locale
setlocale(LC_TIME, preg_split('/s*,s*/', $dateLocale))
echo strftime($dateFormat, $date);     // $date is a UNIX timestamp
setLocale(LC_TIME, $oldlocale);        // restore old locale

Working around the broken sitewide cookies in GS 3.0

The important cookie is only valid for path /admin. There is no (easy?) way to correct the problem for the frontend. However, if you need it for the backend, e.g. linking to a php somewhere in the plugins folder, you can add the following code to your plugin (e.g. directly after setting up the hooks):

if (!myplugin_is_frontend() && myplugin_gsversion() == '3.0') {
  // workaround for GetSimple 3.0:
  if (isset($_COOKIE['GS_ADMIN_USERNAME'])) setcookie('GS_ADMIN_USERNAME', $_COOKIE['GS_ADMIN_USERNAME'], 0, '/');
}

function myplugin_is_frontend() {
  return function_exists('get_site_url');
}

function myplugin_gsversion() {
  @include(GSADMININCPATH.'configuration.php');
  return GSVERSION;
}

Замените myplugin наименованием своего плагина.

Ссылки

На главную Содержание

Страницы этой секции

Разработка плагинов

ru/plugins/tips.1381834443.txt.gz · Last modified: 2013/10/15 10:54 by vladislav