/**
 * Reads a file
 * <pre>
 *  * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons)
 *  * assign : if set, the file will be saved in this variable instead of being output
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-06
 * @package    Dwoo
 */
function functionFetch(Core $dwoo, $file, $assign = null)
{
    if ($file === '') {
        return null;
    }
    if ($policy = $dwoo->getSecurityPolicy()) {
        while (true) {
            if (preg_match('{^([a-z]+?)://}i', $file)) {
                return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
            }
            $file = realpath($file);
            $dirs = $policy->getAllowedDirectories();
            foreach ($dirs as $dir => $dummy) {
                if (strpos($file, $dir) === 0) {
                    break 2;
                }
            }
            return $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING);
        }
    }
    $file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
    $out = file_get_contents($file);
    if ($assign === null) {
        return $out;
    }
    $dwoo->assignInScope($out, $assign);
    return null;
}
/**
 * Ouputs the content captured by the script_capture block
 * <pre>
 *  * name : capture name
 * </pre>
 *
 * Used with the output_script function
 * Example :
 *
 * <code>
 * {script_capture "myscript"}
 *   alert('hello world');
 * {/script_capture}
 * {output_script myscript}
 * </code>
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * This file is released under the LGPL
 * "GNU Lesser General Public License"
 * More information can be found here:
 * {@link http://www.gnu.org/copyleft/lesser.html}
 *
 * @author     Harro van der Klauw <*****@*****.**>
 * @copyright  Copyright (c) 2008, Harro van der Klauw
 * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-09
 * @package    Dwoo
 */
function functionOutputScript(Core $dwoo, $name)
{
    $pre = '<script type="text/javascript" charset="utf-8">';
    $post = '</script>';
    if (!class_exists('\\Dwoo\\Plugins\\Blocks\\BlockScriptCapture')) {
        $dwoo->getLoader()->loadPlugin('script_capture');
    }
    $content = trim(BlockScriptCapture::getScripts($name));
    if (empty($content)) {
        return '';
    }
    return $pre . $content . $post;
}
 /**
  * Constructor, take Core object as param
  * @param Core $core
  */
 public function __construct(Core $core)
 {
     $this->core = $core;
     $this->corePluginDir = Core::DWOO_DIRECTORY . DIRECTORY_SEPARATOR . 'Plugins';
     $this->cacheDir = rtrim($core->getCompileDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     // include class paths or rebuild paths if the cache file isn't there
     $cacheFile = $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php';
     if (file_exists($cacheFile)) {
         $classpath = file_get_contents($cacheFile);
         $this->classPath = unserialize($classpath) + $this->classPath;
     } else {
         $this->rebuildClassPathCache($this->corePluginDir, $cacheFile);
     }
 }
Example #4
0
/**
 * Evaluates the given string as if it was a template
 *
 * Although this plugin is kind of optimized and will
 * not recompile your string each time, it is still not
 * a good practice to use it. If you want to have templates
 * stored in a database or something you should probably use
 * the String class or make another class that
 * extends it
 * <pre>
 *  * var : the string to use as a template
 *  * assign : if set, the output of the template will be saved in this variable instead of being output
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-06
 * @package    Dwoo
 */
function functionEval(Core $dwoo, $var, $assign = null)
{
    if ($var == '') {
        return null;
    }
    $tpl = new String($var);
    $clone = clone $dwoo;
    $out = $clone->get($tpl, $dwoo->readVar('_parent'));
    if ($assign !== null) {
        $dwoo->assignInScope($out, $assign);
    } else {
        return $out;
    }
    return null;
}
/**
 * Reverses a string or an array
 * <pre>
 *  * value : the string or array to reverse
 *  * preserve_keys : if value is an array and this is true, then the array keys are left intact
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-06
 * @package    Dwoo
 */
function functionReverse(Core $dwoo, $value, $preserve_keys = false)
{
    if (is_array($value)) {
        return array_reverse($value, $preserve_keys);
    } elseif (($charset = $dwoo->getCharset()) === 'iso-8859-1') {
        return strrev((string) $value);
    } else {
        $strlen = mb_strlen($value);
        $out = '';
        while ($strlen--) {
            $out .= mb_substr($value, $strlen, 1, $charset);
        }
        return $out;
    }
}
/**
 * Inserts another template into the current one
 * <pre>
 *  * file : the resource name of the template
 *  * cache_time : cache length in seconds
 *  * cache_id : cache identifier for the included template
 *  * compile_id : compilation identifier for the included template
 *  * data : data to feed into the included template, it can be any array and will default to $_root (the current data)
 *  * assign : if set, the output of the included template will be saved in this variable instead of being output
 *  * rest : any additional parameter/value provided will be added to the data array
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.1.0
 * @date       2009-07-18
 * @package    Dwoo
 */
function functionInclude(Core $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array())
{
    if ($file === '') {
        return null;
    }
    if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
        // resource:identifier given, extract them
        $resource = $m[1];
        $identifier = $m[2];
    } else {
        // get the current template's resource
        $resource = $dwoo->getTemplate()->getResourceName();
        $identifier = $file;
    }
    try {
        $include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
    } catch (SecurityException $e) {
        return $dwoo->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING);
    } catch (Exception $e) {
        return $dwoo->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING);
    }
    if ($include === null) {
        return $dwoo->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.', E_USER_WARNING);
    } elseif ($include === false) {
        return $dwoo->triggerError('Include : Resource "' . $resource . '" does not support includes.', E_USER_WARNING);
    }
    if (is_string($data)) {
        $vars = $dwoo->readVar($data);
    } else {
        $vars = $data;
    }
    if (count($rest)) {
        $vars = $rest + $vars;
    }
    $clone = clone $dwoo;
    $out = $clone->get($include, $vars);
    if ($assign !== null) {
        $dwoo->assignInScope($out, $assign);
    }
    foreach ($clone->getReturnValues() as $name => $value) {
        $dwoo->assignInScope($value, $name);
    }
    if ($assign === null) {
        return $out;
    }
    return null;
}
/**
 * Capitalizes the first letter of each word
 * <pre>
 *  * value : the string to capitalize
 *  * numwords : if true, the words containing numbers are capitalized as well
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-03
 * @package    Dwoo
 */
function functionCapitalize(Core $dwoo, $value, $numwords = false)
{
    if ($numwords || preg_match('#^[^0-9]+$#', $value)) {
        return mb_convert_case((string) $value, MB_CASE_TITLE, $dwoo->getCharset());
    } else {
        $bits = explode(' ', (string) $value);
        $out = '';
        while (list(, $v) = each($bits)) {
            if (preg_match('#^[^0-9]+$#', $v)) {
                $out .= ' ' . mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
            } else {
                $out .= ' ' . $v;
            }
        }
        return substr($out, 1);
    }
}
/**
 * Applies various escaping schemes on the given string
 * <pre>
 *  * value : the string to process
 *  * format : escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript and mail
 *  * charset : character set to use for the conversion (applies to some formats only), defaults to the current Dwoo charset
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-06
 * @package    Dwoo
 */
function functionEscape(Core $dwoo, $value = '', $format = 'html', $charset = null)
{
    if ($charset === null) {
        $charset = $dwoo->getCharset();
    }
    switch ($format) {
        case 'html':
            return htmlspecialchars((string) $value, ENT_QUOTES, $charset);
        case 'htmlall':
            return htmlentities((string) $value, ENT_QUOTES, $charset);
        case 'url':
            return rawurlencode((string) $value);
        case 'urlpathinfo':
            return str_replace('%2F', '/', rawurlencode((string) $value));
        case 'quotes':
            return preg_replace("#(?<!\\\\)'#", "\\'", (string) $value);
        case 'hex':
            $out = '';
            $cnt = strlen((string) $value);
            for ($i = 0; $i < $cnt; $i++) {
                $out .= '%' . bin2hex((string) $value[$i]);
            }
            return $out;
        case 'hexentity':
            $out = '';
            $cnt = strlen((string) $value);
            for ($i = 0; $i < $cnt; $i++) {
                $out .= '&#x' . bin2hex((string) $value[$i]) . ';';
            }
            return $out;
        case 'javascript':
            return strtr((string) $value, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\\/'));
        case 'mail':
            return str_replace(array('@', '.'), array('&nbsp;(AT)&nbsp;', '&nbsp;(DOT)&nbsp;'), (string) $value);
        default:
            return $dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "' . $format . '" given.', E_USER_WARNING);
    }
}
Example #9
0
 public function triggerError($message, $level = E_USER_NOTICE)
 {
     if (is_object($this->template)) {
         return parent::triggerError($message, $level);
     }
     trigger_error('Dwoo error : ' . $message, $level);
 }
/**
 * Outputs a mailto link with optional spam-proof (okay probably not) encoding
 * <pre>
 *  * address : target email address
 *  * text : display text to show for the link, defaults to the address if not provided
 *  * subject : the email subject
 *  * encode : one of the available encoding (none, js, jscharcode or hex)
 *  * cc : address(es) to carbon copy, comma separated
 *  * bcc : address(es) to blind carbon copy, comma separated
 *  * newsgroups : newsgroup(s) to post to, comma separated
 *  * followupto : address(es) to follow up, comma separated
 *  * extra : additional attributes to add to the &lt;a&gt; tag
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    2.0
 * @date       2013-09-07
 * @package    Dwoo
 */
function functionMailto(Core $dwoo, $address, $text = null, $subject = null, $encode = null, $cc = null, $bcc = null, $newsgroups = null, $followupto = null, $extra = null)
{
    if (empty($address)) {
        return '';
    }
    if (empty($text)) {
        $text = $address;
    }
    if (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
        throw new Exception('Email: ' . $address . ' is not a valid email address!', E_USER_ERROR);
    }
    // build address string
    $address .= '?';
    if (!empty($subject)) {
        $address .= 'subject=' . rawurlencode($subject) . '&';
    }
    if (!empty($cc)) {
        $address .= 'cc=' . rawurlencode($cc) . '&';
    }
    if (!empty($bcc)) {
        $address .= 'bcc=' . rawurlencode($bcc) . '&';
    }
    if (!empty($newsgroups)) {
        $address .= 'newsgroups=' . rawurlencode($newsgroups) . '&';
    }
    if (!empty($followupto)) {
        $address .= 'followupto=' . rawurlencode($followupto) . '&';
    }
    $address = rtrim($address, '?&');
    // output
    switch ($encode) {
        case 'none':
        case null:
            return '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
        case 'js':
        case 'javascript':
            $str = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
            $len = strlen($str);
            $out = '';
            for ($i = 0; $i < $len; $i++) {
                $out .= '%' . bin2hex($str[$i]);
            }
            return '<script type="text/javascript">eval(unescape(\'' . $out . '\'));</script>';
            break;
        case 'javascript_charcode':
        case 'js_charcode':
        case 'jscharcode':
        case 'jschar':
            $str = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
            $len = strlen($str);
            $out = '<script type="text/javascript">' . "\n<!--\ndocument.write(String.fromCharCode(";
            for ($i = 0; $i < $len; $i++) {
                $out .= ord($str[$i]) . ',';
            }
            return rtrim($out, ',') . "));\n-->\n</script>\n";
            break;
        case 'hex':
            if (strpos($address, '?') !== false) {
                return $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.', E_USER_WARNING);
            }
            $out = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
            $len = strlen($address);
            for ($i = 0; $i < $len; $i++) {
                if (preg_match('#\\w#', $address[$i])) {
                    $out .= '%' . bin2hex($address[$i]);
                } else {
                    $out .= $address[$i];
                }
            }
            $out .= '" ' . $extra . '>';
            $len = strlen($text);
            for ($i = 0; $i < $len; $i++) {
                $out .= '&#x' . bin2hex($text[$i]);
            }
            return $out . '</a>';
        default:
            return $dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>', E_USER_WARNING);
    }
}
Example #11
0
 static function processContacto($contactoDto)
 {
     $errors = array();
     $contacto = new Contacto(NULL, date("Y-m-d H:i:s", time()), true, $contactoDto->nombre, $contactoDto->mail, $contactoDto->telefono, $contactoDto->celular, $contactoDto->asunto, $contactoDto->mensaje, false, false, $contactoDto->tipo);
     $transaction = GenericDao::beginTransaction();
     try {
         BaseDao::createContacto($contacto, $transaction);
         $transaction->commit();
         $dwoo = new Core();
         $contactoDto->logo = AppConfig::logoUrl;
         $template = $dwoo->get($_SERVER["DOCUMENT_ROOT"] . '/views/shared/templates/mails/contact.tpl', (array) $contactoDto);
         Mail::Send('*****@*****.**', BaseAdmin::getContactoMailTitle($contactoDto->tipo), $template);
     } catch (\Exception $ex) {
         $transaction->rollBack();
         $errors = array('Se produjo un error, por favor intentelo más tarde.');
     }
     return $errors;
 }
Example #12
0
 /**
  * returns the parameter map of the given callback, it filters out entries typed as Dwoo and Compiler and turns the rest parameter into a "*"
  *
  * @param callback $callback the function/method to reflect on
  *
  * @return array processed parameter map
  */
 protected function getParamMap($callback)
 {
     if (is_null($callback)) {
         return array(array('*', true));
     }
     if (is_array($callback)) {
         $ref = new \ReflectionMethod(Core::underscoreToCamel($callback[0]), $callback[1]);
     } else {
         $ref = new \ReflectionFunction($callback);
     }
     $out = array();
     foreach ($ref->getParameters() as $param) {
         if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\\Core') {
             continue;
         }
         if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\\Compiler') {
             continue;
         }
         if ($param->getName() === 'rest' && $param->isArray() === true) {
             $out[] = array('*', $param->isOptional(), null);
             continue;
         }
         $out[] = array($param->getName(), $param->isOptional(), $param->isOptional() ? $param->getDefaultValue() : null);
     }
     return $out;
 }
Example #13
0
 /**
  * returns the full compiled file name and assigns a default value to it if
  * required
  *
  * @param Core $dwoo the dwoo instance that requests the file name
  *
  * @return string the full path to the compiled file
  */
 protected function getCompiledFilename(Core $dwoo)
 {
     // no compile id was provided, set default
     if ($this->compileId === null) {
         $this->compileId = $this->name;
     }
     return $dwoo->getCompileDir() . $this->compileId . '.d' . Core::RELEASE_TAG . '.php';
 }
Example #14
0
 /**
  * loads a plugin file
  *
  * @param string $class       the plugin name, without the prefix (Block|block|Function|function)
  * @param bool   $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it has just been added, defaults to true
  *
  * @return bool
  * @throws Exception\PluginException
  */
 public function loadPlugin($class, $forceRehash = true)
 {
     // An unknown class was requested (maybe newly added) or the
     // include failed so we rebuild the cache. include() will fail
     // with an uncatchable error if the file doesn't exist, which
     // usually means that the cache is stale and must be rebuilt,
     // so we check for that before trying to include() the plugin.
     // Convert class name to CamelCase
     $class = Core::underscoreToCamel($class);
     // Check entry exist in $this->classPath
     $match = preg_grep('/^(Block|block|Function|function)?(' . $class . '+)/i', array_keys($this->classPath));
     $index = array_values($match);
     // Entry doesn't exist, try to rebuild cache
     $included_files = get_included_files();
     if (!isset($index[0]) || !isset($this->classPath[$index[0]]) || !is_readable($this->classPath[$index[0]]) || !in_array($this->classPath[$index[0]], $included_files)) {
         if ($forceRehash) {
             // Rebuild cache
             $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php');
             foreach ($this->paths as $path => $file) {
                 $this->rebuildClassPathCache($path, $file);
             }
             // Check entry exist after rebuilding cache
             $match = preg_grep('/^(Block|block|Function|function)?(' . $class . '+)/i', array_keys($this->classPath));
             $index = array_values($match);
             if (isset($index[0])) {
                 if (isset($this->classPath[$index[0]])) {
                     include $this->classPath[$index[0]];
                     return true;
                 }
             }
         }
         throw new PluginException(sprintf(PluginException::FORGOT_BIND, $class), E_USER_NOTICE);
         return false;
     }
     return false;
 }
 /**
  * returns the plugin type of a plugin and adds it to the used plugins array if required
  * @param string $name plugin name, as found in the template
  * @throws Security\Exception
  * @throws Exception
  * @return int $pluginType as a multi bit flag composed of the \Dwoo\plugin types constants
  */
 protected function getPluginType($name)
 {
     $pluginType = -1;
     // Security Policy
     if ($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty') || $this->securityPolicy !== null && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false) {
         $phpFunc = true;
     } else {
         if ($this->securityPolicy !== null && function_exists($name) && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) === false) {
             throw new Security\Exception('Call to a disallowed php function : ' . $name);
         }
     }
     // Plugin type
     while ($pluginType <= 0) {
         if (isset($this->templatePlugins[$name])) {
             $pluginType = Core::TEMPLATE_PLUGIN | Core::COMPILABLE_PLUGIN;
         } else {
             if (isset($this->customPlugins[$name])) {
                 $pluginType = $this->customPlugins[$name]['type'] | Core::CUSTOM_PLUGIN;
             } else {
                 if (file_exists(Core::DWOO_DIRECTORY . '/Plugins/Blocks/Block' . ucfirst($name) . '.php')) {
                     try {
                         $reflectionClass = new \ReflectionClass(Core::PLUGIN_BLOCK_CLASS_PREFIX_NAME . ucfirst($name));
                         $pluginType = Core::BLOCK_PLUGIN;
                         if ($reflectionClass->implementsInterface('\\Dwoo\\ICompilable\\Block')) {
                             $pluginType |= Core::COMPILABLE_PLUGIN;
                         }
                     } catch (Exception $e) {
                     }
                 } else {
                     if (file_exists(Core::DWOO_DIRECTORY . '/Plugins/Functions/Function' . ucfirst($name) . '.php')) {
                         try {
                             $reflectionClass = new \ReflectionClass(Core::PLUGIN_FUNC_CLASS_PREFIX_NAME . ucfirst($name));
                             $pluginType = Core::CLASS_PLUGIN;
                             if ($reflectionClass->implementsInterface('\\Dwoo\\ICompilable')) {
                                 $pluginType |= Core::COMPILABLE_PLUGIN;
                             }
                         } catch (Exception $e) {
                         }
                     } else {
                         if (function_exists('smarty_modifier_' . $name) !== false) {
                             $pluginType = Core::SMARTY_MODIFIER;
                         } else {
                             if (function_exists('smarty_function_' . $name) !== false) {
                                 $pluginType = Core::SMARTY_FUNCTION;
                             } else {
                                 if (function_exists('smarty_block_' . $name) !== false) {
                                     $pluginType = Core::SMARTY_BLOCK;
                                 } else {
                                     if ($pluginType === -1) {
                                         try {
                                             $this->core->getLoader()->loadPlugin($name, isset($phpFunc) === false);
                                             $classPath = $this->core->getLoader()->getClassPath();
                                             if ($match = preg_grep('/^(Block|Function)?(' . $name . '+)/i', array_keys($classPath))) {
                                                 $index = array_values($match);
                                                 $className = function ($file) {
                                                     $namespace = null;
                                                     $classes = '';
                                                     $tokens = token_get_all(file_get_contents($file));
                                                     for ($i = 0; $i < count($tokens); $i++) {
                                                         switch ($tokens[$i][0]) {
                                                             case T_NAMESPACE:
                                                                 $i += 2;
                                                                 while ($tokens[$i][0] === T_STRING || $tokens[$i][0] === T_NS_SEPARATOR) {
                                                                     $namespace .= $tokens[$i++][1];
                                                                 }
                                                                 break;
                                                             case T_INTERFACE:
                                                             case T_CLASS:
                                                             case T_TRAIT:
                                                                 $i += 2;
                                                                 if ($namespace) {
                                                                     $classes = '\\' . $namespace . '\\' . $tokens[$i][1];
                                                                 } else {
                                                                     $classes = '\\' . $tokens[$i][1];
                                                                 }
                                                                 break;
                                                         }
                                                     }
                                                     return $classes;
                                                 };
                                                 $callback = $className($classPath[$index[0]]);
                                                 $rc = new \ReflectionClass($callback);
                                                 if (strpos($index[0], 'Block') !== false) {
                                                     $pluginType = Core::BLOCK_PLUGIN;
                                                     if ($rc->implementsInterface('\\Dwoo\\ICompilable\\Block')) {
                                                         $pluginType |= Core::COMPILABLE_PLUGIN;
                                                     }
                                                 } else {
                                                     if (strpos($index[0], 'Function') !== false) {
                                                         $pluginType = Core::CLASS_PLUGIN;
                                                         if ($rc->implementsInterface('\\Dwoo\\ICompilable')) {
                                                             $pluginType |= Core::COMPILABLE_PLUGIN;
                                                         }
                                                     }
                                                 }
                                             }
                                         } catch (Exception $e) {
                                             if (isset($phpFunc)) {
                                                 $pluginType = Core::NATIVE_PLUGIN;
                                             } else {
                                                 if (is_object($this->core->getPluginProxy()) && $this->core->getPluginProxy()->handles($name)) {
                                                     $pluginType = Core::PROXY_PLUGIN;
                                                     break;
                                                 } else {
                                                     throw $e;
                                                 }
                                             }
                                         }
                                     } else {
                                         throw new Exception('Plugin "' . $name . '" could not be found');
                                     }
                                     $pluginType++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (($pluginType & Core::COMPILABLE_PLUGIN) === 0 && ($pluginType & Core::NATIVE_PLUGIN) === 0 && ($pluginType & Core::PROXY_PLUGIN) === 0) {
         $this->addUsedPlugin($name, $pluginType);
     }
     return $pluginType;
 }
Example #16
0
 static function processRecuperoClave($mail)
 {
     $errors = array();
     try {
         $user = SecurityDao::getUserByMail($mail);
         $code = base64_encode($user->id . '|' . $user->createDate . '|' . $user->mail);
         $link = 'https://servicios.diarco.com.ar/turnos/views/generarClave.php?c=' . $code;
         $user->link = $link;
         $subject = 'Diarco, proceso de recupero de contraseña';
         $dwoo = new Core();
         $template = $dwoo->get($_SERVER["DOCUMENT_ROOT"] . '/views/shared/templates/mails/passwordRecovery.tpl', (array) $user);
         Mail::Send($user->mail, $subject, $template);
     } catch (\Exception $ex) {
         array_push($errors, $ex->getMessage());
     }
     return $errors;
 }
 /**
  * Set charset
  *
  * @param string $charset
  * @return $this
  */
 public function setCharset($charset)
 {
     $this->_engine->setCharset($charset);
     return $this;
 }
Example #18
0
 static function addFormEntryMessage($messageDto)
 {
     $transaction = NULL;
     $result = array();
     $dwoo = new Core();
     try {
         $transaction = GenericDao::beginTransaction();
         $message = new FormEntryMessage(null, date("Y-m-d H:i:s", time()), true, $messageDto->proveedorId, $messageDto->entryId, $messageDto->formId, $messageDto->message, $messageDto->sender);
         FormDao::addFormEntryMessage($message, $transaction);
         $entry = FormAdmin::getFormEntryDetailById($messageDto->formId, $messageDto->entryId);
         if ($messageDto->sender == MessageSender::cliente) {
             FormAdmin::changeProveedorEntryState($messageDto->proveedorId, $messageDto->formId, $messageDto->entryId, \entities\ClienteState::enviada, \entities\ProveedorState::recibida);
             $transaction->commit();
             $proveedor = ProveedorDao::getProveedorById($messageDto->proveedorId);
             $user = SecurityDao::getUserById($proveedor->usuarioId);
             $dest = 'proveedor';
         } else {
             FormAdmin::changeProveedorEntryState($messageDto->proveedorId, $messageDto->formId, $messageDto->entryId, \entities\ClienteState::enProceso, \entities\ProveedorState::enProceso);
             $transaction->commit();
             $user = SecurityDao::getUserById($entry->userId);
             $dest = 'cliente';
         }
         $user->logo = AppConfig::logoUrl;
         $user->producto = $entry->producto;
         $code = base64_encode($user->id . '|' . $user->createDate . '|' . $user->mail . '|' . $dest . '|' . date("Y-m-d H:i:s", time()));
         $link = 'http://' . getenv('HTTP_HOST') . APP_FOLDER . '/views/client/AutoLoginManager.php?c=' . $code;
         $user->link = $link;
         $template = $dwoo->get($_SERVER["DOCUMENT_ROOT"] . '/views/shared/templates/mails/newMessage.tpl', (array) $user);
         Mail::Send($user->mail, 'Aladinnus, nuevo mensaje', $template);
     } catch (\Exception $ex) {
         $transaction->rollBack();
         $result = array($ex->getMessage());
     }
     return $result;
 }
Example #19
0
 /**
  * Render a string
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return null|string
  *
  * @throws CoreException
  * @throws Exception
  * @throws \Exception
  */
 public function render($template, array $locals = array())
 {
     $templateObject = new Str($template);
     return $this->dwoo->get($templateObject, $locals);
 }
Example #20
0
 /**
  * returns the full compiled file name and assigns a default value to it if
  * required
  *
  * @param Core $dwoo the dwoo instance that requests the file name
  *
  * @return string the full path to the compiled file
  */
 protected function getCompiledFilename(Core $dwoo)
 {
     // no compile id was provided, set default
     if ($this->compileId === null) {
         $this->compileId = str_replace('../', '__', strtr($this->getResourceIdentifier(), '\\:', '/-'));
     }
     return $dwoo->getCompileDir() . $this->compileId . '.d' . Core::RELEASE_TAG . '.php';
 }
Example #21
0
 /**
  * this is used at run time to check whether method calls are allowed or not
  *
  * @param Core   $dwoo   dwoo instance that calls this
  * @param object $obj    any object on which the method must be called
  * @param string $method lowercased method name
  * @param array  $args   arguments array
  *
  * @return mixed result of method call or unll + E_USER_NOTICE if not allowed
  */
 public function callMethod(Core $dwoo, $obj, $method, $args)
 {
     foreach ($this->allowedMethods as $class => $methods) {
         if (!isset($methods[$method])) {
             continue;
         }
         if ($obj instanceof $class) {
             return call_user_func_array(array($obj, $method), $args);
         }
     }
     $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()');
     return null;
 }
 static function sendMail($to, $subject, $name, $title, $detail)
 {
     $dwoo = new Core();
     $data = new \stdClass();
     $data->name = $name;
     $data->title = $title;
     $data->detail = $detail;
     try {
         $template = $dwoo->get($_SERVER["DOCUMENT_ROOT"] . '/views/shared/templates/mails/solicitud.tpl', (array) $data);
         Mail::Send($to, $subject, $template);
     } catch (\Exception $ex) {
     }
 }