<commit_before><?php

class API {

  function pageLoad($f3) {
    $db= $f3->get('DBH');
    $page= new DB\SQL\Mapper($db, 'page');
    if (!$page->load(array('slug=?', $_REQUEST['slug']))) {
      $page->slug= $_REQUEST['slug'];
      $page->format= 'markdown';
    }
    $ret= $page->cast();
    $ret['rendered']= Markdown::instance()->convert($ret['content']);
    echo jsonp($f3, $ret);
  }

  function pageSave($f3) {
    $db= $f3->get('DBH');
    $page= new DB\SQL\Mapper($db, 'page');
    $page->load(array('slug=?', $_REQUEST['slug']));
    foreach ($_REQUEST as $k => $v) {
      if ($page->exists($k)) $page->set($k, $v);
    }
    $page->save();
    $ret= $page->cast();
    $ret['rendered']= Markdown::instance()->convert($ret['content']);
    echo jsonp($f3, $ret);
  }

  function productLoad($f3) {
    $db= $f3->get('DBH');
    $obj= new DB\SQL\Mapper($db, 'product');
    if (!$obj->load(array('id=?', $f3->get('REQUEST.id')))) {
      $obj->slug= $_REQUEST['slug'];
    }
    $ret= $obj->cast();
    echo jsonp($f3, $ret);
  }

  function productSave($f3) {
    $db= $f3->get('DBH');
    $obj= new DB\SQL\Mapper($db, 'product');
    $obj->load(array('id=?', $f3->get('REQUEST.id')));
    foreach ($_REQUEST as $k => $v) {<commit_msg>Render variables when editing page<commit_after><?php

class API {

  function pageLoad($f3) {
    $db= $f3->get('DBH');
    $page= new DB\SQL\Mapper($db, 'page');
    if (!$page->load(array('slug=?', $_REQUEST['slug']))) {
      $page->slug= $_REQUEST['slug'];
      $page->format= 'markdown';
    }
    $ret= $page->cast();
    $text= Template::instance()->resolve($ret['content']);
    $ret['rendered']= Markdown::instance()->convert($text);
    echo jsonp($f3, $ret);
  }

  function pageSave($f3) {
    $db= $f3->get('DBH');
    $page= new DB\SQL\Mapper($db, 'page');
    $page->load(array('slug=?', $_REQUEST['slug']));
    foreach ($_REQUEST as $k => $v) {
      if ($page->exists($k)) $page->set($k, $v);
    }
    $page->save();
    $ret= $page->cast();
    $ret['rendered']= Markdown::instance()->convert($ret['content']);
    echo jsonp($f3, $ret);
  }

  function productLoad($f3) {
    $db= $f3->get('DBH');
    $obj= new DB\SQL\Mapper($db, 'product');
    if (!$obj->load(array('id=?', $f3->get('REQUEST.id')))) {
      $obj->slug= $_REQUEST['slug'];
    }
    $ret= $obj->cast();
    echo jsonp($f3, $ret);
  }

  function productSave($f3) {
    $db= $f3->get('DBH');
    $obj= new DB\SQL\Mapper($db, 'product');
    $obj->load(array('id=?', $f3->get('REQUEST.id')));
    foreach ($_REQUEST as $k => $v) {
{'fraction_non_alphanumeric': 0.2723735408560311, 'fraction_numerical': 0.010116731517509728, 'mean_word_length': 3.5105263157894737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1715678', 'n_tokens_mistral': 990, 'n_tokens_neox': 997, 'n_words': 176}