/** * check to see if file exists from twig * @param $file * @param $twig * @return bool */ public static function twig_asset_exists($file, $twig) { try { $twig->loadTemplate($file); return true; } catch (Exception $e) { if (class_exists('HW_Logger')) { HW_Logger::add_debug($e->getFile() . ':' . $e->getLine() . '=>' . $e->getMessage()); } return false; } }
/** * export wxr data for the module * @param null $xml */ public function _export_wxr_data($xml = null) { //update new data belong to this module into pre-shortcodes using by installer add_shortcode('hw_image', array($this, '_parse_image_shortcode')); try { //fetch category, tag,terms $this->fetch_terms($xml); $this->fetch_authors($xml); //fetch authors to create new $this->export_wxr_data($xml); } catch (Exception $e) { HW_Logger::log_file($e->getMessage()); HW_Logger::log_file($e->getFile() . ':' . $e->getLine()); HW_Logger::log_file($e->getTraceAsString()); //An array of the backtrace() } }
static function _test() { HW_Logger::log_file('------------'); }
function __print($d) { HW_Logger::out($d); }
/** * cast to simplexmlelement object * @param $file * @param bool $break_error * @return WP_Error */ public static function read_simplexml_object($file, $break_error = true) { $internal_errors = libxml_use_internal_errors(true); $old_value = null; if (function_exists('libxml_disable_entity_loader')) { $old_value = libxml_disable_entity_loader(true); } if ($file instanceof SimpleXMLElement) { $xml = $file; } elseif ($file instanceof DOMDocument) { #$xml = simplexml_import_dom($file, 'SimpleXMLElement'); //safe way $xml = simplexml_load_string($file->saveXML(), 'SimpleXMLElement', LIBXML_NOCDATA); //third param can be: LIBXML_NOCDATA | LIBXML_NOBLANKS } elseif (is_string($file)) { $dom = new DOMDocument(); if (file_exists($file)) { $xml_content = file_get_contents($file); } elseif (is_string($file)) { $xml_content = $file; } $success = $xml_content ? $dom->loadXML($xml_content) : false; if (!$success || isset($dom->doctype)) { HW_Logger::log_file(libxml_get_errors()); //log errors if ($break_error) { return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'hw-importer'), libxml_get_errors()); } else { return false; } } $xml = simplexml_import_dom($dom); unset($dom); } if (!is_null($old_value)) { libxml_disable_entity_loader($old_value); } // halt if loading produces an error if (empty($xml)) { if ($break_error) { return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'hw-importer'), libxml_get_errors()); } else { return false; } } //store namespace $namespaces = self::valid_namespaces($xml); return (object) array('xml' => $xml, 'namespaces' => $namespaces); }