<commit_before><?php
require_once '../wci-helper-functions.php';

class CRM_Wci_WidgetCode {

  static function get_widget_realtime_code($widgetId) {
    $data = CRM_Wci_BAO_Widget::getWidgetData($widgetId);
    $template = CRM_Core_Smarty::singleton();
    $template->assign('wciform', $data);
    $template->assign('cpageId', $data['button_link_to']);
//    $template->assign('preview', $preview);

    if ($data["override"] == '0') {
      $template->template_dir[] = getWciWidgetTemplatePath();
      $wcidata = $template->fetch('wciwidget.tpl');
    } else {
      $wcidata = $template->fetch('string:' . html_entity_decode($data['custom_template']));
    }
    $code = json_encode($wcidata);
    CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $code);
    return $code;
  }
  
  static function get_widget_code($embedId, $preview=0) {
    
    if($preview) {
      /**On preview time controller is called from create widget 
          form so id will be widget id */
      $code = CRM_Wci_WidgetCode::get_widget_realtime_code($embedId);
    } else {
      $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embedId);
      $code = CRM_Wci_BAO_WidgetCache::getWidgetCache($widgetId);

      $tsDiff = CRM_Wci_BAO_WidgetCache::getCurrentTsDiff($widgetId);
      $cacheTime = civicrm_api3('setting', 'getValue', 
          array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout'));
      if(($tsDiff > $cacheTime)||(empty($code))) {
        $code = CRM_Wci_WidgetCode::get_widget_realtime_code($widgetId);
      }
    }
    return $code;
  }
}

<commit_msg>Beta 2 bug fixes. 31243. added agpl license and  widget cache feature<commit_after><?php
require_once '../wci-helper-functions.php';

class CRM_Wci_WidgetCode {

  static function get_widget_realtime_code($widgetId, $preview) {
    $data = CRM_Wci_BAO_Widget::getWidgetData($widgetId);
    $template = CRM_Core_Smarty::singleton();
    $template->assign('wciform', $data);
    $template->assign('cpageId', $data['button_link_to']);
    $template->assign('preview', $preview);

    if ($data["override"] == '0') {
      $template->template_dir[] = getWciWidgetTemplatePath();
      $wcidata = $template->fetch('wciwidget.tpl');
    } else {
      $wcidata = $template->fetch('string:' . html_entity_decode($data['custom_template']));
    }
    $code = json_encode($wcidata);
    CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $code);
    return $code;
  }
  
  static function get_widget_code($embedId, $preview=0) {
    
    if($preview) {
      /**On preview time controller is called from create widget 
          form so id will be widget id */
      $code = CRM_Wci_WidgetCode::get_widget_realtime_code($embedId, $preview);
    } else {
      $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embedId);
      $code = CRM_Wci_BAO_WidgetCache::getWidgetCache($widgetId);

      $tsDiff = CRM_Wci_BAO_WidgetCache::getCurrentTsDiff($widgetId);
      $cacheTime = civicrm_api3('setting', 'getValue', 
          array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout'));
      if(($tsDiff > $cacheTime)||(empty($code))) {
        $code = CRM_Wci_WidgetCode::get_widget_realtime_code($widgetId, $preview);
      }
    }
    return $code;
  }
}


{'fraction_non_alphanumeric': 0.15427509293680297, 'fraction_numerical': 0.0037174721189591076, 'mean_word_length': 4.109177215189874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6849224', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1072, 'n_words': 172}