function recompile($path) { global $AR, $templateStore; $dh = opendir($path); $objectID = pathToObjectID($path); while (false !== ($file = readdir($dh))) { if ($file != "." && $file != "..") { $f = $path . $file; if (substr($file, -strlen(".pinp")) == ".pinp" && is_file($f)) { $templateName = substr($file, 1, -strlen(".pinp")); echo "Recompiling {$templateName}<br>\n"; $pinp_code = file_get_contents($f); $compiler = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_"); $optimized = sprintf($AR->PINPtemplate, $compiled); $compiled = $compiler->compile(strtr($pinp_code, "\r", "")); if ($compiler->error) { showCompilerError($compiler, $path . $file); } else { $optimized = sprintf($AR->PINPtemplate, $compiled); $templateStore->write($optimized, $objectID, $templateName . ".inc"); } } else { if (is_dir($f) && $file != "CVS" && $file != ".svn") { recompile("{$f}/"); } } } } closedir($dh); }
function _create_function($args, $code) { global $AR; $pinp = new pinp($AR->PINP_Functions, 'var_', '$AR_this->_'); $safe_args = $pinp->compileFuncCallArgs("{$args}", "funcCallArgs"); $pinp = new pinp($AR->PINP_Functions, 'var_', '$AR_this->_'); $safe_code = substr($pinp->compile("<pinp>{$code}</pinp>"), 5, -2); return create_function($safe_args, $safe_code); }
protected function preg_replace_compile($pattern, $replacement) { global $AR; include_once $this->store->get_config("code") . "modules/mod_pinp.phtml"; preg_match("/^\\s*(.)/", $pattern, $regs); $delim = $regs[1]; if (@eregi("\\{$delim}[^{$delim}]*\\{$delim}.*e.*" . '$', $pattern)) { $pinp = new pinp($AR->PINP_Functions, 'local->', '$AR_this->_'); return substr($pinp->compile("<pinp>{$replacement}</pinp>"), 5, -2); } else { return $replacement; } }
public function compile($path, $name) { global $AR; $arpath = path::collapse($path); if (strpos($arpath, $this->path, 0) !== 0) { return ar('error')->raiseError('invalide path for loading template', 500); } $realpath = $this->config['path'] . substr($arpath, strlen($this->path)); $realpath = realpath($realpath) . '/'; $template = file_get_contents($realpath . $name); require_once AriadneBasePath . "/modules/mod_pinp.phtml"; $pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_"); // FIXME error checking $compiled = $pinp->compile(strtr($template, "\r", "")); $compiled = sprintf($AR->PINPtemplate, $compiled); return $compiled; }
function storeObject($path, &$objdata) { global $AR; /* step 1 if not skip data load object if exists copy data into object else create new object fi save fi */ if (!($this->config['skipdata'] === true)) { debug('WDDX work data', 'all'); if ($id = $this->store->exists($path)) { debug("WDDX data: object exists", 'all'); if (!is_object($object)) { $object = current($this->store->call("system.get.phtml", array(), $this->store->get($path))); } if ($object->lastchanged <= $objdata['lastchanged'] || $this->config['forcedata'] === true) { $this->print_verbose(" ( updating ) \n"); $tmpconfig = $object->data->config; unset($object->data); $object->data = $objdata['data']; $object->data->config->grants = $tmpconfig->grants; $object->data->config->pinp = $tmpconfig->pinp; $object->data->config->templates = $tmpconfig->templates; $object->type = $objdata['type']; $object->vtype = $objdata['vtype']; $object->lastchanged = $objdata['lastchanged']; $object->size = $objdata['size']; $object->priority = $objdata['priority']; $object->type = $objdata['type']; $object->save($objdata['properties']); } else { $this->print_verbose(" ( skipping ) \n"); } } else { debug("WDDX data: object doesn't exists", 'all'); $this->print_verbose(" ( saving ) \n"); $parent = $this->store->make_path($path, '..'); if ($parent == $path) { $parent = '..'; } $object = $this->store->newobject($path, $parent, $objdata['type'], $objdata['data'], 0, $objdata['lastchanged'], $objdata['vtype'], $objdata['size'], $objdata['priority']); $object->arIsNewObject = true; if (!$object->store->is_supported('fulltext')) { unset($objdata['properties']['fulltext']); } $object->save($objdata['properties']); if ($object->error) { debug("WDDX data: error during save"); debug("WDDX data: " . $object->error); } debug("WDDX data: done save"); } unset($object); } /* step 2 if not skip templates if removeold remove old templates fi if update if forced save new templates else save new templates when newer fi else save new templates fi fi */ if (!($this->config['skiptemplates'] === true)) { debug('WDDX work templates', 'all'); if ($id = $this->store->exists($path)) { debug("WDDX templates: object exists", 'all'); if (!is_object($object)) { $object = current($this->store->call("system.get.phtml", array(), $this->store->get($path))); } $templates = $object->store->get_filestore("templates"); /* purge templates */ if ($this->config['dellalltemplates'] === true) { /* delete all current templates */ $templates->purge($object->id); $object->data->config->pinp = array(); $object->data->config->templates = array(); } /* do something about those templates */ if (is_Array($objdata['templates'])) { $this->print_verbose(" Templates:\n"); foreach ($objdata['templates'] as $type => $tval) { if (is_array($tval)) { foreach ($tval as $function => $nval) { if (is_array($nval)) { foreach ($nval as $language => $val) { $file = $type . "." . $function . "." . $language; debug("WDDX templates: " . $object->id . "working on template {$file}", 'all'); $pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_"); $template = base64_decode($val['template']); $compiled = $pinp->compile(strtr($template, "\r", "")); $this->print_verbose(' '); $this->print_verbose("[" . $file . "]: "); if ($templates->exists($object->id, $file)) { if ($val['mtime'] >= $templates->mtime($object->id, $file) || $this->config['forcedata'] === true) { debug('WDDX templates: overwrite existing template', 'all'); $this->print_verbose(" saving\n"); $templates->write($template, $object->id, $file . ".pinp"); $templates->touch($object->id, $file . ".pinp", $val['mtime']); $templates->write($compiled, $object->id, $file); $templates->touch($object->id, $file, $val['mtime']); $object->data->config->pinp[$type][$function][$language] = $object->id; /* is it a default template ? */ if ($objdata['data']->config->templates[$type][$function][$language] === $objdata['id']) { $object->data->config->templates[$type][$function][$language] = $object->id; } else { // remove pinp template from default templates list if (isset($object->data->config->templates[$type][$function][$language])) { unset($object->data->config->templates[$type][$function][$language]); if (count($object->data->config->templates[$type][$function]) == 0) { unset($object->data->config->templates[$type][$function]); if (count($object->data->config->templates[$type]) == 0) { unset($object->data->config->templates[$type]); } } } } } else { $this->print_verbose(" skipping\n"); } } else { debug('WDDX templates: create template', 'all'); $this->print_verbose(" saving\n"); $templates->write($template, $object->id, $file . ".pinp"); $templates->touch($object->id, $file . "pinp", $val['mtime']); $templates->write($compiled, $object->id, $file); $templates->touch($object->id, $file, $val['mtime']); $object->data->config->pinp[$type][$function][$language] = $object->id; /* is it a default template ? */ if ($objdata['data']->config->templates[$type][$function][$language] === $objdata['id']) { $object->data->config->templates[$type][$function][$language] = $object->id; } else { // remove pinp template from default templates list if (isset($object->data->config->templates[$type][$function][$language])) { unset($object->data->config->templates[$type][$function][$language]); if (count($object->data->config->templates[$type][$function]) == 0) { unset($object->data->config->templates[$type][$function]); if (count($object->data->config->templates[$type]) == 0) { unset($object->data->config->templates[$type]); } } } } } } } else { debug("WDDX template: nval != array", 'all'); } } } else { debug("WDDX template: tval != array", 'all'); } } } else { debug("WDDX template: templates != array", 'all'); } $changed = true; } } /* step 3 if not skip grants if removeold remove old grants fi if exists remove fi save grant fi */ if (!($this->config['skipgrants'] === true)) { debug('WDDX work grants', 'all'); if ($id = $this->store->exists($path)) { debug('WDDX grants: yeah the path exists', 'all'); if (!is_object($object)) { $object = current($this->store->call("system.get.phtml", array(), $this->store->get($path))); } if (is_array($objdata['data']->config->grants)) { $this->print_verbose(" Grants: installing\n"); $object->data->config->grants = $objdata['data']->config->grants; $changed = true; } } } /* step 4 if not skip files if removeold remove old files fi if update if forced save new files else save new files when newer fi else save new files fi fi */ if (!($this->config['skipfiles'] === true)) { debug('WDDX work files', 'all'); if ($id = $this->store->exists($path)) { if (!is_object($object)) { $object = current($this->store->call("system.get.phtml", array(), $this->store->get($path))); } $files = $object->store->get_filestore("files"); debug('WDDX files: yeah the path exists', 'all'); if (is_Array($objdata[files]) && count($objdata[files]) > 0) { $this->print_verbose(" Files:\n"); foreach ($objdata[files] as $key => $val) { $this->print_verbose(' '); $this->print_verbose("[" . $key . "]: "); if ($files->exists($object->id, $key)) { if ($val['mtime'] >= $files->mtime($object->id, $key) || $this->config['forcefiles'] === true) { debug('WDDX files: overwrite existing file', 'all'); $this->print_verbose(" updating\n"); $files->write(base64_decode($val[file]), $object->id, $key); $files->touch($object->id, $file, $val['mtime']); } else { $this->print_verbose(" skipping\n"); } } else { $this->print_verbose(" saving\n"); debug('WDDX files: create template', 'all'); $files->write(base64_decode($val[file]), $object->id, $key); debug("WDDX files: touch {$file} with" . $val['mtime'], 'all'); $files->touch($object->id, $file, $val['mtime']); } } } } } // save the object if ($changed) { $object->save(); } }
public function testReferences() { $template = <<<'EOD' <pinp> $frop = 'frop'; $foo = &$frop; $bar =& $frop; $frop = 'frml'; return array( $foo, $bar ); </pinp> EOD; $compiler = new pinp("header", "object->", "\$object->_"); $res = $compiler->compile($template); $this->assertNull($compiler->error); $ret = eval(' $object = new ar_core_pinpSandbox($this); ?' . '>' . $res); $this->assertEquals(['frml', 'frml'], $ret); }
function esiEvaluate($test) { global $AR; // print_r($test); $test = preg_replace('!(\\$\\([^)]*\\))!', '\'$1\'', $test); // echo "[2[" . print_r($test, true) . "]]"; $test = ESI::esiExpression($test); // echo "[[" . print_r($test, true) . "]]"; require_once $AR->dir->install . "/lib/modules/mod_pinp.phtml"; $pinp = new pinp($AR->PINP_Functions, "esilocal->", "\$AR_ESI_this->_"); $pinp->allowed_functions = array(); $pinp->language_types['array'] = false; $pinp->language_types['object'] = false; $compiled = $pinp->compile("<pinp>" . $test . "</pinp>"); $compiled = preg_replace("/^<\\?php(.*)\\?" . ">\$/s", '$1', $compiled); // FIXME: Is eval after the pinp compiler save enough to run? $result = eval("return (" . $compiled . ");"); return $result; }