Ejemplo n.º 1
0
 public static function get_shortcodes($content, $form_id)
 {
     if (empty($form_id) || strpos($content, '[') === false) {
         // don't continue if there are no shortcodes to check
         return array(array());
     }
     $tagregexp = array('deletelink', 'detaillink', 'evenodd', 'get', 'entry_count', 'event_date');
     $form_id = (int) $form_id;
     $form_ids = array($form_id);
     //get linked form ids
     $fields = FrmProFormsHelper::has_repeat_field($form_id, false);
     foreach ($fields as $field) {
         if (FrmField::is_option_true($field, 'form_select')) {
             $form_ids[] = $field->field_options['form_select'];
             $tagregexp[] = $field->id;
             $tagregexp[] = $field->field_key;
         }
         unset($field);
     }
     foreach ($form_ids as $form_id) {
         $fields = FrmField::get_all_for_form($form_id, '', 'include');
         foreach ($fields as $field) {
             $tagregexp[] = $field->id;
             $tagregexp[] = $field->field_key;
         }
     }
     $tagregexp = implode('|', $tagregexp) . '|';
     $tagregexp .= FrmFieldsHelper::allowed_shortcodes();
     if (!ini_get('safe_mode')) {
         // make sure the backtrack limit is as least at the default
         $backtrack_limit = ini_get('pcre.backtrack_limit');
         if ($backtrack_limit < 1000000) {
             ini_set('pcre.backtrack_limit', 1000000);
         }
     }
     preg_match_all("/\\[(if |foreach )?({$tagregexp})\\b(.*?)(?:(\\/))?\\](?:(.+?)\\[\\/\\])?/s", $content, $matches, PREG_PATTERN_ORDER);
     // run conditional and foreach first
     $new_order = $matches[0];
     $move_up = array();
     foreach ($new_order as $short_key => $tag) {
         $conditional = preg_match('/^\\[if/s', $matches[0][$short_key]) ? true : false;
         $foreach = preg_match('/^\\[foreach/s', $matches[0][$short_key]) ? true : false;
         if ($conditional || $foreach) {
             $move_up[$short_key] = $tag;
         }
     }
     if (!empty($move_up)) {
         $matches[0] = $move_up + $matches[0];
     }
     return $matches;
 }
Ejemplo n.º 2
0
 /**
  * After the sub entry and parent entry are created, we can update the parent id field
  * @since 2.0
  */
 public static function update_parent_id($entry_id, $form_id)
 {
     $form_fields = FrmProFormsHelper::has_field('form', $form_id, false);
     $section_fields = FrmProFormsHelper::has_repeat_field($form_id, false);
     if (!$form_fields && !$section_fields) {
         return;
     }
     $form_fields = array_merge($section_fields, $form_fields);
     $entry = FrmEntry::getOne($entry_id, true);
     if (!$entry || $entry->form_id != $form_id) {
         return;
     }
     $sub_ids = array();
     foreach ($form_fields as $field) {
         if (!isset($entry->metas[$field->id])) {
             continue;
         }
         $ids = maybe_unserialize($entry->metas[$field->id]);
         if (!empty($ids)) {
             $sub_ids = array_merge($ids, $sub_ids);
         }
         unset($field);
     }
     if (!empty($sub_ids)) {
         $where = array('id' => $sub_ids);
         FrmDb::get_where_clause_and_values($where);
         array_unshift($where['values'], $entry_id);
         global $wpdb;
         $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_items SET parent_item_id = %d' . $where['where'], $where['values']));
     }
 }