Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-10-31 18:56:08

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Problem with register_callback "author_ui" in textpattern 4.6.2

Hello,
I’ve got a plugin which extends the user data, with some information. The callback is registered in this way:

register_callback('s2l_bio_admin', 'author_ui', 'extend_detail_form');

But the forms of this function do not appear. In 4.5.7 it worked, as it should. No warnings or errors in PHP. Tested it with both, PHP7 and PHP 5.5. The Plugin is “Admin + Public” with a “Load order” of “5”. The code is a little bit longer, so I hesitate to post the full code here.

function s2l_bio_admin($event, $step, $data, $rs) {
  global $language;

  $txp_user = $rs["name"];

  include_once $_SERVER['DOCUMENT_ROOT']."/textpattern/publish/taghandlers.php";

[...]

What did I oversee?

Offline

#2 2017-10-31 20:16:55

etc
Developer
Registered: 2010-11-11
Posts: 3,357
Website

Re: Problem with register_callback "author_ui" in textpattern 4.6.2

Hi, any other plugin registered to the same event.step?

Offline

#3 2017-10-31 20:50:58

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: Problem with register_callback "author_ui" in textpattern 4.6.2

hm, I think not:

     24,61 |     0,02 | [Callback_event: 'admin_side', step='theme_name', pre='0']
     24,88 |     0,01 | [Callback_event: 'admin', step='author_edit', pre='1']
     25,06 |     0,01 | [Callback_event: 'admin_side', step='html_title', pre='0']
     25,43 |     5,89 | [Callback_event: 'admin_side', step='head_end', pre='0']
     31,34 |     0,03 | [Callback_event: 'admin_side', step='pagetop', pre='0']
     31,86 |     0,01 | [Callback_event: 'admin_side', step='header', pre='0']
     31,89 |     0,01 | [Callback_event: 'admin_side', step='pagetop_end', pre='0']
     31,91 |     0,01 | [Callback_event: 'admin_side', step='main_content', pre='0']
     32,34 |     0,01 | [Callback_event: 'admin_ui', step='inputlabel.login_name', pre='0']
     32,42 |     0,01 | [Callback_event: 'admin_ui', step='inputlabel.real_name', pre='0']
     32,48 |     0,01 | [Callback_event: 'admin_ui', step='inputlabel.login_email', pre='0']
     32,59 |     0,01 | [Callback_event: 'admin_help', step='about_privileges', pre='0']
     32,64 |     0,01 | [Callback_event: 'admin_ui', step='inputlabel.privileges', pre='0']
     32,66 |     1,12 | [Callback_event: 'author_ui', step='extend_detail_form', pre='0']
     33,76 |     0,01 | 	[Callback_event: 'admin_ui', step='inputlabel.language', pre='0']
     33,91 |     0,01 | [Callback_event: 'admin', step='author_edit', pre='0']
     33,93 |     0,01 | [Callback_event: 'admin_side', step='main_content_end', pre='0']
     33,99 |     0,01 | [Callback_event: 'admin_side', step='footer', pre='0']
     34,01 |     0,02 | [Callback_event: 'admin_side', step='body_end', pre='0']

I made a test, whether the function is called or not by putting an echo inside. That worked, so my suggestion, that there is something wrong with this callback was probably wrong.

So, anyway, the code goes like this:

function s2l_bio_admin($event, $step, $data, $rs) {
  global $language;

  $txp_user = $rs["name"];

  include_once $_SERVER['DOCUMENT_ROOT']."/textpattern/publish/taghandlers.php";

  // Получаем значения дополнительных полей
  $rs = safe_row("*", "txp_users", "name='$txp_user'");

  // Добавляем свои языковые фразы
  switch ($language) {
    case "ru-ru":
      $show_url_title = "Текст для ссылки";
      $show_author_title = "Показать форму обратной связи в статье?<br/>(По умолчанию выключено)";
      $sex_txt["label"] = "Пол";
      $sex_txt["female"] = "Женский";
      $sex_txt["male"] = "Мужской";
      $sex_txt["del"] = "Удалить";
      $sex_txt["confirm"] = "Удалить картинку?";
      $sex_txt["txt_del"] = "Будет<br/>удалена";
      $sex_txt["txt_del_cancel"] = "Отменить";
      break;
    case "uk-ua":
      $show_url_title = "Текст для посилання";
      $show_author_title = "Показати форму зворотного зв'язку в статті? <br/> (За замовчуванням вимкнено)";
      $sex_txt["label"] = "Стать";
      $sex_txt["female"] = "Жіноча";
      $sex_txt["male"] = "чоловіча";
      $sex_txt["del"] = "Видалити";
      $sex_txt["confirm"] = "Видалити картинку?";
      $sex_txt["txt_del"] = "Буде<br/>видалена";
      $sex_txt["txt_del_cancel"] = "Скасувати";
      break;
    case "de-de":
      $show_url_title = "Text für den Link";
      $show_author_title = "Anzeige von Kontaktformular unter dem Artikel? <br/> (Standardeinstellung: aus)";
      $sex_txt["label"] = "Anrede";
      $sex_txt["female"] = "Frau";
      $sex_txt["male"] = "Herr";
      $sex_txt["del"] = "Löschen";
      $sex_txt["confirm"] = "Bild löschen?";
      $sex_txt["txt_del"] = "Es wird<br/>gelöscht";
      $sex_txt["txt_del_cancel"] = "Stornieren";
      break;
    default:
      $show_url_title = "Text for the link";
      $show_author_title = "Display Customer feedback in the form of articles? <br/> (Default: off)";
      $sex_txt["label"] = "Gender";
      $sex_txt["female"] = "Female";
      $sex_txt["male"] = "Male";
      $sex_txt["del"] = "Delete";
      $sex_txt["confirm"] = "Delete picture?";
      $sex_txt["txt_del"] = "It will<br/>be deleted";
      $sex_txt["txt_del_cancel"] = "Cancel";
  }

  // Добавляем enctype в форму
  $msg = "
<script>
$(document).ready(function() {
  $('#user_edit').attr('enctype', 'multipart/form-data');
  $('.txp-edit').attr('style', 'position: relative;');
  $('#desc').attr('style', 'height: 150px;');

  $('.s2l_bio_btn_delete').click(function () {
    if ( $(this).val() == '".$sex_txt["del"]."' ) {
      if ( confirm('".$sex_txt["confirm"]."') ) {
        $('.s2l-img').attr('style','opacity:0.2;');
        $('.s2l-img').after('<p>".$sex_txt["txt_del"]."</p>');
        $('.s2l-img + p').attr('style', 'position: absolute;right: 40px;');
        $('.s2l_bio_btn_delete').attr('value', '".$sex_txt["txt_del_cancel"]."');
        $('#s2l-bio-del').val('".$rs['image']."');
      }
    } else {
        $('.s2l-img').attr('style','opacity:1;');
        $('.s2l-img + p').hide();
        $('.s2l_bio_btn_delete').attr('value', '".$sex_txt["del"]."');
        $('#s2l-bio-del').val('0');
    }
  });
});
</script>
";

  $msg .= "<style>img.s2l-img {width:100px;height:auto;margin-bottom:5px;float:right;} .s2l_bio_btn_delete {float: right;clear: both;}</style>";



  $show_author = "";
  if ($rs['show_author'] == "1") {
    $show_author = " checked";
  }



  $msg .= '
<p class="edit-description">
  <span class="edit-label">
    <label for="s2l_url">'.gTxt('url').'</label>
  </span>
  <span class="edit-value">
    <input type="text" name="s2l_url" id="s2l_url" value="'.$rs['url'].'"/>
  </span>
</p>
<p class="edit-description">
  <span class="edit-label">
    <label for="s2l_title_url">'.$show_url_title.'</label>
  </span>
  <span class="edit-value">
    <input type="text" name="title_url" id="s2l_title" value="'.$rs['title_url'].'"/>
  </span>
</p>
<p class="edit-description">
  <span class="edit-label">
    <label for="gender">'.$sex_txt["label"].'</label>
  </span>
  <span class="edit-value">
    <select name="gender" id="gender">

      <option value="0"';
        if ($rs['gender'] == 0) {
          $msg .= ' selected';
        }
  $msg .= '
      ></option>

      <option value="1"';
        if ($rs['gender'] == 1) {
          $msg .= ' selected';
        }
  $msg .= '
      >'.$sex_txt["female"].'</option>

      <option value="2"';
        if ($rs['gender'] == 2) {
          $msg .= ' selected';
        }
  $msg .= '
      >'.$sex_txt["male"].'</option>
    </select>
  </span>
</p>

<p class="edit-description">
  <span class="edit-label">
    <label for="desc">'.gTxt('description').'</label>
  </span>
  <span class="edit-value">
    <textarea size="32" name="description" id="desc">'.$rs['description'].'</textarea>
  </span>
</p>
<p class="edit-description">
  <span class="edit-label">
    <label for="s2l_avatar">'.gTxt('upload_image').' (JPG)</label>
  </span>
  <span class="edit-value">
    <input type="file" name="avatar" id="s2l_avatar"/>
  </span>
</p>
<p class="show-author">
  <span class="edit-label">
    <label for="s2l_avatar">'.$show_author_title.'</label>
  </span>
  <span class="edit-value">
    <input type="checkbox" name="show_author"'.$show_author.'/>
  </span>
</p>
';

// выводим картинку
$atts = array('id' => $rs['image'], 'class' => "s2l-img");
$msg .= thumbnail($atts);

// Выводим кнопку удаления картинки
  $msg .= '<input type="hidden" value="0" name="s2l-bio-del" id="s2l-bio-del"/>';

if ($rs['image'] > 0) {
  $msg .= '
    <input type="button" value="'.$sex_txt["del"].'" class="s2l_bio_btn_delete"/>
  ';
}



  return $msg."\n<br/>".$data;
}

Offline

#4 2017-10-31 22:12:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

Re: Problem with register_callback "author_ui" in textpattern 4.6.2

whocarez wrote #307588:

I’ve got a plugin which extends the user data, with some information.

And smd_bio can’t help?!?

Assuming there’s a good reason you want to roll your own plugin…

safe_row("*", "txp_users", "name='$txp_user'")

Just as a general point, you should probably sanitize input unless you’re sure it’s clean already:

$rs = safe_row("*", "txp_users", "name='".doSlash($txp_user)."'")

Why is the code overwriting $rs passed into the function with its own call to safe_row() to fetch the same information? Not that it probably matters, but just for sanity’s sake, can’t it save a DB call and use $rs directly?

You could also save yourself some escaping and potential quoting issues in the HTML by using heredoc:

$msg = script_js(<<<EOJS
$(document).ready(function() {
  $('#user_edit').attr('enctype', 'multipart/form-data');
  $('.txp-edit').attr('style', 'position: relative;');
  $('#desc').attr('style', 'height: 150px;');

  $('.s2l_bio_btn_delete').click(function () {
    if ( $(this).val() == '{$sex_txt["del"]}' ) {
      if ( confirm('{$sex_txt["confirm"]}') ) {
...
    }
  });
});
EOJS;
);

That’d help clean things up a bit and remove any potential for a rogue quote – although since there are no syntax errors, I guess it’s okay as-is.

All I can say is that the code works fine on my 4.6.2 and 4.7.0-dev (well, after spewing a load of undefined index warnings) so it’s a little baffling why it’s not running on yours, especially since you’ve covered all the usual bases: admin+public type, plugin enabled, ensured the callback is registered on the admin side only, no other clashing plugins, …

Very odd.

Last edited by Bloke (2017-10-31 22:13:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2017-11-01 12:37:21

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: Problem with register_callback "author_ui" in textpattern 4.6.2

Thanks for the hints. To be honestly, it’s not my code, I only tried to figure out, why it stopped working. So, maybe I should investigate the problem in a testing environment.

Offline

Board footer

Powered by FluxBB