public function compile(&$entry) { self::$compiling = $this->get('id'); $driver = Symphony::ExtensionManager()->create('reflectionfield'); $xpath = $driver->getXPath($entry, $this->get('xsltfile'), $this->get('fetch_associated_counts')); self::$compiling = 0; $entry_id = $entry->get('id'); $field_id = $this->get('id'); $expression = $this->get('expression'); $replacements = array(); // Find queries: preg_match_all('/\\{[^\\}]+\\}/', $expression, $matches); // Find replacements: foreach ($matches[0] as $match) { $result = @$xpath->evaluate('string(' . trim($match, '{}') . ')'); if (!is_null($result)) { $replacements[$match] = trim($result); } else { $replacements[$match] = ''; } } // Apply replacements: $value = str_replace(array_keys($replacements), array_values($replacements), $expression); // Apply formatting: if (!($value_formatted = $this->applyFormatting($value))) { $value_formatted = General::sanitize($value); } $data = array('handle' => Lang::createHandle($value), 'value' => $value, 'value_formatted' => $value_formatted); // Save: $result = Symphony::Database()->update($data, "tbl_entries_data_{$field_id}", "`entry_id` = '{$entry_id}'"); $entry->setData($field_id, $data); }
public function compile($entry) { self::$ready = false; $xpath = $this->_driver->getXPath($entry); self::$ready = true; $entry_id = $entry->get('id'); $field_id = $this->get('id'); $expression = $this->get('expression'); $replacements = array(); // Find queries: preg_match_all('/\\{[^\\}]+\\}/', $expression, $matches); // Find replacements: foreach ($matches[0] as $match) { $results = @$xpath->query(trim($match, '{}')); if ($results->length) { $replacements[$match] = $results->item(0)->nodeValue; } else { $replacements[$match] = ''; } } // Apply replacements: $value = str_replace(array_keys($replacements), array_values($replacements), $expression); // Apply formatting: if (!($value_formatted = $this->applyFormatting($value))) { $value_formatted = General::sanitize($value); } // Save: $result = $this->Database->update(array('handle' => Lang::createHandle($value), 'value' => $value, 'value_formatted' => $value_formatted), "tbl_entries_data_{$field_id}", "\n\t\t\t\t`entry_id` = '{$entry_id}'\n\t\t\t"); }