render() public méthode

Executes a named rendering process by running each process step in sequence and aggregating the results. The View class comes with 3 built-in processes: 'all', 'template', and 'element'. The 'all' process is the default two-step rendered view, where a template is wrapped in a layout containing a header and footer.
See also: lithium\template\View::_conditions()
See also: lithium\template\View::$_processes
See also: lithium\template\View::$_steps
public render ( string $process, array $data = [], array $options = [] ) : string
$process string A named set of rendering steps defined in the `$_processes` array.
$data array An associative array of data to be rendered in the set of templates.
$options array Options used when rendering. Available keys are as follows: - `'type'` _string_: The type of content to render. Defaults to `'html'`. - `'layout'` _string_: The name of the layout to use in the default two-step rendering process. Defaults to `null`. - `'template'` _string_: The name of the template to render. Defaults to `null`. - `'context'` _array_: An associative array of information to inject into the rendering context. - `'paths'` _array_: A nested array of paths to use for rendering steps. The top-level keys should match the `'path'` key in a step configuration (i.e.: `'template'`, `'layout'`, or `'element'`), and the second level is an array of path template strings to search (can be a string if there's only one path). These path strings generally take the following form: `'{:library}/views/{:controller}/{:template}.{:type}.php'`. These template strings are specific to the `File` loader, but can take any form useful to the template loader being used.
Résultat string Returns the result of the rendering process, typically by rendering a template first, then rendering a layout (using the default configuration of the `'all'` process).
Exemple #1
0
 public function testFullRenderNoLayout()
 {
     $view = new View(array('loader' => 'Simple', 'renderer' => 'Simple'));
     $result = $view->render('all', array('type' => 'auth', 'success' => 'true'), array('template' => '<{:type}>{:success}</{:type}>'));
     $expected = '<auth>true</auth>';
     $this->assertEqual($expected, $result);
 }
 public function cold()
 {
     $email = "support@" . COMPANY_URL;
     if ($handle = opendir(VANITY_OUTPUT_DIR)) {
         while (false !== ($entry = readdir($handle))) {
             if ($entry != "." && $entry != "..") {
                 unlink(VANITY_OUTPUT_DIR . $entry);
             }
         }
         closedir($handle);
     }
     $cmd = '/bin/vanitygen -i -o "' . VANITY_OUTPUT_DIR . $email . '_0.txt" 1';
     exec($cmd);
     $file = file_get_contents(VANITY_OUTPUT_DIR . $email . '_0.txt', FILE_USE_INCLUDE_PATH);
     $qrcode = new QRcode();
     $fc = explode("\n", $file);
     foreach ($fc as $key => $value) {
         if (stristr($value, "Address")) {
             $addressp = str_replace(" ", "", str_replace("\r", "", str_replace("Address:", "", $value)));
             $qrcode->png($addressp, QR_OUTPUT_DIR . $addressp . '.png', 'H', 7, 2);
         }
         if (stristr($value, "Privkey")) {
             $privkey = str_replace(" ", "", str_replace("\r", "", str_replace("Privkey:", "", $value)));
             $qrcode->png($privkey, QR_OUTPUT_DIR . $privkey . '.png', 'H', 7, 2);
         }
     }
     $data = array('0' => array('address' => $addressp, 'key' => $privkey));
     $view = new View(array('paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     echo $view->render('all', compact('data'), array('controller' => 'print', 'template' => 'print', 'type' => 'pdf', 'layout' => 'print'));
     unlink(QR_OUTPUT_DIR . $addressp . '.png');
     unlink(QR_OUTPUT_DIR . $privkey . '.png');
     unlink(VANITY_OUTPUT_DIR . $email . '_0.txt');
     return compact('user', 'data');
 }
Exemple #3
0
 function sendEmailTo($email = null, $compact = null, $controller = null, $template = null, $subject = null, $from = null, $mail1 = null, $mail2 = null, $mail3 = null, $attach = null)
 {
     $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
     $body = $view->render('template', compact('compact'), array('controller' => $controller, 'template' => $template, 'type' => 'mail', 'layout' => false));
     $transport = Swift_MailTransport::newInstance();
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setSubject($subject);
     $message->setFrom($from);
     $message->setTo($email);
     if ($attach != null) {
         $swiftAttachment = Swift_Attachment::fromPath($attach);
         $message->attach($swiftAttachment);
     }
     if ($mail1 != null) {
         $message->addBcc($mail1);
     }
     if ($mail2 != null) {
         $message->addBcc($mail2);
     }
     if ($mail3 != null) {
         $message->addBcc($mail3);
     }
     $message->setBody($body, 'text/html');
     $mailer->send($message);
 }
Exemple #4
0
 /**
  * Renders the sitemap response based on the received request and configuration
  * @param object $request The request object
  * @throws Exception
  * @return object Response
  */
 public static function render($request)
 {
     $config = Libraries::get('li3_sitemap');
     $sitemap = Sitemap::generate($config);
     $viewOptions = Sitemap::configureView($request, $config);
     $response = new Response(compact('request'));
     $view = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php', 'template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     $response->body = $view->render('all', compact('sitemap'), $viewOptions);
     return $response;
 }
	/**
	 * Outputs a flash message using a template. The message will be cleared afterwards.
	 * With defaults settings it looks for the template 
	 * `app/views/elements/flash_message.html.php`. If it doesn't exist, the  plugin's view 
	 * at `li3_flash_message/views/elements/flash_message.html.php` will be used. Use this 
	 * file as a starting point for your own flash message element. In order to use a 
	 * different template, adjust `$options['type']` and `$options['template']` to your needs.
	 *
	 * @param string [$key] Optional message key. 
	 * @param array [$options] Optional options.
	 *              - type: Template type that will be rendered.
	 *              - template: Name of the template that will be rendered.
	 *              - data: Additional data for the template.
	 *              - options: Additional options that will be passed to the renderer.
	 * @return string Returns the rendered template.
	 */
	public function output($key = 'default', array $options = array()) {
		$defaults = array(
			'type' => 'element',
			'template' => 'flash_message',
			'data' => array(),
			'options' => array(),
			'paths' => array(
				'layout' => 'blank'
			)
		);
		$options += $defaults;
		
		$storage = $this->_classes['storage'];
		//$view = $this->_context->view();
		// need a new view because the one from context will already have its paths changed
		$view = new View(array(
			'paths' => array(
			    'template' => '{:library}/views/elements/{:template}.{:type}.php',
			    'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
			)
		));

		
		$output = '';
		$type = array($options['type'] => $options['template']);
		$flash = $storage::get($key);
		
		if (!empty($flash)) {
			$data = $options['data'] + array('message' => $flash['message']) + $flash['atts'];
			$storage::clear($key);
		
			try {
				$output = $view->render($type, $data, $options['options']);
			} catch (\Exception $e) {
				$output = $view->render($type, $data, array('library' => 'li3_flash_message'));
			}
		}
		return $output;
	}
Exemple #6
0
 /**
  * We want to use our own little helper so that everything is shorter to write and
  * so we can use fancier messages with JavaScript.
  *
  * @param $options
  * @return HTML String
  */
 public function flash($options = array())
 {
     $defaults = array('key' => 'default', 'options' => array('type' => 'growl', 'fade_delay' => '8000', 'pnotify_opacity' => '.8'));
     $options += $defaults;
     $message = '';
     $flash = FlashMessage::read($options['key']);
     if (!empty($flash)) {
         $message = $flash['message'];
         FlashMessage::clear($options['key']);
     }
     $view = new View(array('paths' => array('template' => '{:library}/views/elements/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     return $view->render('all', array('options' => $options['options'], 'message' => $message), array('library' => 'li3b_core', 'template' => 'flash_message', 'type' => 'html', 'layout' => 'blank'));
 }
Exemple #7
0
 public function run()
 {
     $files_to_zip = array("/backup/SIICrypto/details.bson", "/backup/SIICrypto/details.metadata.json", "/backup/SIICrypto/logins.bson", "/backup/SIICrypto/logins.metadata.json", "/backup/SIICrypto/orders.bson", "/backup/SIICrypto/orders.metadata.json", "/backup/SIICrypto/pages.bson", "/backup/SIICrypto/pages.metadata.json", "/backup/SIICrypto/parameters.bson", "/backup/SIICrypto/parameters.metadata.json", "/backup/SIICrypto/requests.bson", "/backup/SIICrypto/requests.metadata.json", "/backup/SIICrypto/reasons.bson", "/backup/SIICrypto/reasons.metadata.json", "/backup/SIICrypto/system.indexes.bson", "/backup/SIICrypto/system.users.bson", "/backup/SIICrypto/system.users.metadata.json", "/backup/SIICrypto/settings.bson", "/backup/SIICrypto/settings.metadata.json", "/backup/SIICrypto/trades.bson", "/backup/SIICrypto/trades.metadata.json", "/backup/SIICrypto/transactions.bson", "/backup/SIICrypto/transactions.metadata.json", "/backup/SIICrypto/users.bson", "/backup/SIICrypto/users.metadata.json", "/.greencoin/wallet.dat");
     //if true, good; if false, zip creation failed
     $result = $this->create_zip($files_to_zip, BACKUP_DIR . 'Backup.zip', true);
     $filename = BACKUP_DIR . 'Backup.zip';
     $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
     $body = $view->render('template', compact('filename'), array('controller' => 'admin', 'template' => 'backup', 'type' => 'mail', 'layout' => false));
     $transport = Swift_MailTransport::newInstance();
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setSubject("Data Backup: " . COMPANY_URL);
     $message->setFrom(array(SUPPORT => 'Data Backup: ' . COMPANY_URL));
     $message->setTo("*****@*****.**");
     $message->addBcc(MAIL_1);
     $message->addBcc(MAIL_2);
     $message->addBcc(MAIL_3);
     $message->attach(Swift_Attachment::fromPath($filename));
     $message->setBody($body, 'text/html');
     $mailer->send($message);
 }
Exemple #8
0
 public static function terminate()
 {
     static::initSession();
     static::initAuth();
     static::$_data['end'] = microtime(true);
     static::$_data['environment'] = Environment::get();
     static::$_data['events.count'] = count(static::$_data['events']);
     static::$_data['db.count'] = count(static::$_data['db']);
     static::$_data['runtime'] = static::$_data['end'] - static::$_data['start'];
     static::$_data['memory.end'] = memory_get_usage(true);
     static::$_data['memory.usage'] = memory_get_peak_usage(true);
     static::$_data['log.count'] = count(static::$_data['log']);
     if (!Environment::is('production') && static::$_view) {
         try {
             echo static::$_view->render(array('element' => 'debug_bar'));
         } catch (\lithium\template\TemplateException $e) {
             $view = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php')));
             echo $view->render(array('element' => 'debug_bar'), array(), array('library' => 'li3_debug'));
         }
     }
 }
Exemple #9
0
 public function testNolayout()
 {
     $view = new View(array('loader' => 'lithium\\tests\\mocks\\template\\view\\adapters\\TestRenderer', 'renderer' => 'lithium\\tests\\mocks\\template\\view\\adapters\\TestRenderer', 'paths' => array('template' => '{:library}/tests/mocks/template/view/adapters/{:template}.html.php', 'layout' => false)));
     $options = array('template' => 'testFile', 'library' => LITHIUM_LIBRARY_PATH . '/lithium');
     $result = $view->render('all', array(), $options);
     $expected = 'This is a test.';
     $this->assertEqual($expected, $result);
     $templateData = TestRenderer::$templateData;
     $expectedPath = LITHIUM_LIBRARY_PATH;
     $expectedPath .= '/lithium/tests/mocks/template/view/adapters/testFile.html.php';
     $expected = array(array('type' => 'template', 'params' => array('template' => 'testFile', 'library' => LITHIUM_LIBRARY_PATH . '/lithium', 'type' => 'html'), 'return' => $expectedPath));
     $this->assertEqual($expected, $templateData);
     $renderData = TestRenderer::$renderData;
     $expected = array(array('template' => $expectedPath, 'data' => array(), 'options' => array('template' => 'testFile', 'library' => $options['library'], 'type' => 'html', 'layout' => NULL, 'context' => array())));
     $this->assertTrue($renderData[0]['data']['h'] instanceof \Closure);
     unset($renderData[0]['data']['h']);
     $this->assertEqual($expected, $renderData);
 }
Exemple #10
0
 public function updateaddress()
 {
     if (!$this->request->query['recordid']) {
         return $this->render(array('json' => array("Error" => "recordid not specified")));
     }
     if (!$this->request->query['walletid']) {
         return $this->render(array('json' => array("Error" => "walletid not specified")));
     }
     if (!$this->request->query['pk0']) {
         return $this->render(array('json' => array("Error" => "pk0 not specified")));
     }
     if (!$this->request->query['pk1']) {
         return $this->render(array('json' => array("Error" => "pk1 not specified")));
     }
     if (!$this->request->query['pk2']) {
         return $this->render(array('json' => array("Error" => "pk2 not specified")));
     }
     $coin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $security = (int) 2;
     $publickeys = array($this->request->query['pk0'], $this->request->query['pk1'], $this->request->query['pk2']);
     $createMultiSig = $coin->createmultisig($security, $publickeys);
     $data = array('msx' => $createMultiSig);
     $conditions = array('walletid' => $this->request->query['walletid']);
     Details::update($data, $conditions);
     //////////// Send Email //////////////////////////////////////////
     $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
     $body = $view->render('template', compact('email', 'verification', 'name'), array('controller' => 'users', 'template' => 'confirm', 'type' => 'mail', 'layout' => false));
     $transport = Swift_MailTransport::newInstance();
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setSubject("Verification of email from " . COMPANY_URL);
     $message->setFrom(array(NOREPLY => 'Verification email ' . COMPANY_URL));
     $message->setTo($Users->email);
     $message->addBcc(MAIL_1);
     $message->addBcc(MAIL_2);
     $message->addBcc(MAIL_3);
     $message->setBody($body, 'text/html');
     $mailer->send($message);
     //////////////////////////////////////////////////////////////////
     return $this->render(array('json' => array("success" => 1)));
 }
Exemple #11
0
                if (in_array($library, $li3_perf['skip']['library'])) {
                    $skip = true;
                }
            }
            // Check to see if the toolbar should be shown for this controller
            if (isset($li3_perf['skip']['controller'])) {
                if (in_array($controller, $li3_perf['skip']['controller'])) {
                    $skip = true;
                }
            }
            // Check to see if the toolbar should be shown for this action
            if (isset($li3_perf['skip']['action'])) {
                if (in_array($action, $li3_perf['skip']['action'])) {
                    $skip = true;
                }
            }
        }
        if ($skip || !isset($result->body[0])) {
            return $result;
        }
        $timers = Data::get('timers') + array('li3_perf_start' => 0, 'li3_perf_end' => 0, 'li3_perf_start_dispatch' => 0, 'li3_perf_has_route' => 0, 'li3_perf_start_call' => 0, 'li3_perf_end_call' => 0, '_filter_for_variables' => 0, '_filter_for_queries' => 0);
        $View = new View(array('paths' => array('template' => '{:library}/views/elements/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
        $toolbar = $View->render('all', array('timers' => $timers += array('dispatch_cycle' => $timers['li3_perf_end'] - $timers['li3_perf_start_dispatch'], 'routing' => $timers['li3_perf_has_route'] - $timers['li3_perf_start_dispatch'], 'call' => isset($timers['li3_perf_end_call']) && isset($timers['li3_perf_start_call']) ? $timers['li3_perf_end_call'] - $timers['li3_perf_start_call'] : 0, 'complete_load_with_li3_perf' => microtime(true) - $timers['li3_perf_start'], 'complete_load' => $timers['li3_perf_end'] - $timers['li3_perf_start'] - $timers['_filter_for_variables'] - $timers['_filter_for_queries']), 'vars' => array('request' => $params['request']->params, 'view' => Data::get('view_vars')), 'queries' => Data::get('queries')), array('library' => 'li3_perf', 'template' => 'toolbar', 'layout' => 'default'));
        if (preg_match('/<!--\\s*LI3_PERF_TOOLBAR\\s*-->/si', $result->body[0], $match)) {
            $result->body[0] = str_replace($match[0], $toolbar, $result->body[0]);
        } else {
            $result->body[0] = $toolbar . $result->body[0];
        }
    }
    return $result;
});
Logger::config(array(
    'default' => array('adapter' => 'File')
));

/**
 * Log all queries passed to the MongoDB adapter.
 */
$MongoDb = Connections::get('default');
$MongoDb->applyFilter('read', function($self, $params, $chain) use (&$MongoDb) {
    $result = $chain->next($self, $params, $chain);

    if (method_exists($result, 'data')) {
        /*Logger::write('info',
            json_encode($params['query']->export($MongoDb) + array('result' => $result->data()))        );  
            */
            //var_dump($params['query']->export($MongoDb) + array('result' => $result->data()));
       
  		$view = new View(array('loader' => 'Simple', 'renderer' => 'Simple'));
  		echo $view->render(array('element' => '<script type="text/javascript">console.dir({:data});</script>'), array(
      		'data' => json_encode(array_filter($params['query']->export($MongoDb)) + array_filter(array('result' => $result->data())))
  		));
       
       //echo \lithium\analysis\Debugger::trace();  // would run a trace
       
       // TODO: make this render later on. so it doesn't put the javascript before <html>         
            
    }       return $result;
});
?>
Exemple #13
0
	/**
	 * render() allows you to render a view template or external URL's content inline with the template it was called from.
	 *
	 * @param $options array[required]
	 * @return Mixed the html/css from the rendered page/view template or JavaScript code with an AJAX call to load local content or false if something went wrong
	*/
	public function render($options=array()) {
		$defaults = array('url' => null, 'curl_options' => array(), 'method' => 'php', 'library' => 'common', 'views_folder' => 'blocks' . DIRECTORY_SEPARATOR . 'static', 'template' => null, 'layout' => 'blank', 'type' => 'html', 'admin' => false);
		$options += $defaults;
		
		/** 
		 *  Method by default is set to php, meaning we are going to get the content for the block now and render it with the page.
		 *  This allows us to cache the block content because the server is aware of it.
		 *  Both the normal "File" renderer to render templates can be used and also a custom "Curl" renderer that can be used 
		 *  to load any URL using the cURL library.
		 */
		if($options['method'] == 'php') {
			// By default, missing
			$template_path = array(
				MINERVA_APP_PATH . DIRECTORY_SEPARATOR .  'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_missing' . DIRECTORY_SEPARATOR . 'missing_block_template.{:type}.php'
			);
			
			// We're going to try to grab the block template from common (note by default it's checking blocks/static)
			array_unshift($template_path, MINERVA_APP_PATH . DIRECTORY_SEPARATOR .  'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $options['views_folder'] . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
			// If requesting a template from a specific library, put that ahead in the list to check first
			if(!empty($options['library'])) {
				array_unshift($template_path, MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $options['library'] . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $options['views_folder'] . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');				
			} 
			
			// For admin blocks, check the admin paths first IF the admin flag was set to true (can not render admin blocks without explicitly saying to do so)
			if($options['admin'] === true) {
				// "admin" blocks have templates saved in minerva/views/blocks/static and this is the default place to look
				array_unshift($template_path, MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $options['views_folder'] . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
				// but we can override those in the common library's "_admin" folder
				array_unshift($template_path, MINERVA_APP_PATH . DIRECTORY_SEPARATOR .  'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_admin' . DIRECTORY_SEPARATOR . $options['views_folder'] . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
			}
			
			// Now a similar thing for the layout templates, but we want to use empty layouts because we don't want <html> tags etc. but we will still cascade and check a few locations
			// NOTE: This layout isn't a "static" layout, it's just an empty "blank" one... It can be changed but the paths aren't looking in the layouts/static folder.
			// This is because a block isn't necessarily "static" content. It can be, but doesn't have to be. Static folders are used for the templates because blocks can be static and menus are ALWAYS static.
			$layout_path = array(
				MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php',
				MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'views'. DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php',
				MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_missing' . DIRECTORY_SEPARATOR . 'missing_layout.{:type}.php'
			);
			
			// If a template was specified, we need to set the paths and our renderer becomes File.
			if(!empty($options['template'])) { 
				$viewOptions['renderer'] = 'File'; // Should be by default, but ensure it is.
				$viewOptions['library'] = $options['library']; // The defaults will set this to null or 'static', but each library can have its own
				$viewOptions['paths'] = array(
			        //'template' => '{:library}/views/'.$options['folder'].'/{:template}.{:type}.php',
				'template' => $template_path,
			        //'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
				'layout' => $layout_path
			    );			    
			}
			// var_dump($viewOptions['paths']); // <-- helpful info
			
			// If a URL was specified, then we definitely don't want to use the File renderer, we want to use the Curl adapter.
			// Also ensure that both a url and template weren't specified, if so, use the template File renderer (above).
			if((!empty($options['url'])) && (empty($options['template']))) {
				$viewOptions['renderer'] = 'Curl'; 
			}
			
			// Instantiate a View class instance with the options we'll need for the renderer, paths, etc.
			$view = new View($viewOptions);
			
			return $view->render('all', array('content' => 'this is not used'), $options);
		}
		
		/** 
		 *  However, we can also set the method to ajax, meaning JavaScript is written to the page instaed and the user gets  
		 *  the data. This won't allow us to cache the block content, but it also allows the rest of the page to load first 
		 *  instead of waiting on the block content to load before continuing on to other parts of the page. 
		 *  
		 *  NOTE: You can't call remote hosts due to security restrictions. So this may not be the method for everyone.
		 *  But if multiple http get requests to the web server isn't particularly a problem, this could make for a very
		 *  fast loading, nice user experience, while at the same time being a very easy way to load content into your block area.
		 */ 
		if($options['method'] == 'ajax') {	
			
			// Find the URL to load() with JavaScript 
			//if(!empty($options['requestAction'])) { 
				
			//}
			
			// TODO: add a spinner graphic, use a $.ajax() and make the success remove the spinner
			// jQuery should be included in the layout already in noConflict mode			
			$ajax_code = '<script type="text/javascript">jQuery(document).ready(function($) {';					
			$ajax_code .= '$(\'#result\').load(\''.$options['url'].'\');'; // NOTE: this can be used to load an external URL			
			$ajax_code .= '});</script>';
			
			return $ajax_code;

		}
		
	}
 /**
  * This renders a a block.
  *
  *
  * @param string $position The block position identifier
  * @param array $options
  * @return string HTML code for the menu
  */
 public function render($position = null, $data = array(), $options = array())
 {
     $defaults = array('cache' => false, 'wrapperId' => false);
     $options += $defaults;
     if (empty($position) || !is_string($position)) {
         return '';
     }
     // set the cache key for the menu
     $cache_key = 'li3b_blocks.' . $position;
     $blocks = false;
     // if told to use the block content from cache
     if (!empty($options['cache'])) {
         $blocks = Cache::read('default', $cache_key);
     }
     // if the content hasn't been set in cache or it was empty for some reason, get a fresh copy of its data
     if (empty($blocks)) {
         $blocks = Block::staticBlock($position);
     }
     // if using cache, write the menu data to the cache key
     if (!empty($options['cache'])) {
         Cache::write('default', $cache_key, $blocks, $options['cache']);
     }
     $string = "\n";
     if ($options['wrapperId']) {
         $string .= '<div id="' . $options['wrapperId'] . '">';
     }
     foreach ($blocks as $block) {
         if (isset($block['options']['wrapperId'])) {
             $string .= "\n\t" . '<div id="' . $block['options']['wrapperId'] . '">';
         }
         // Blocks can be very simple and contain all the content in the array.
         if (is_string($block['content'])) {
             $string .= "\n\t\t" . $block['content'];
         }
         // Or, they can point to an element view template. These are essentially like elements, only they can have layout templates as well.
         if (is_array($block['content'])) {
             if (isset($block['content']['template'])) {
                 $elementOptions = isset($block['content']['options']) ? $block['content']['options'] : array();
                 if (isset($block['content']['library'])) {
                     $elementOptions['library'] = $block['content']['library'];
                 }
                 $elementOptions['layout'] = isset($block['content']['layout']) ? $block['content']['layout'] : 'blank';
                 $elementOptions['template'] = $block['content']['template'];
                 $appConfig = Libraries::get(true);
                 $paths = array('layout' => array('{:library}/views/layouts/{:layout}.{:type}.php', $appConfig['path'] . '/views/layouts/{:layout}.{:type}.php'), 'template' => array($appConfig['path'] . '/views/_libraries/' . $elementOptions['library'] . '/blocks/{:template}.{:type}.php', '{:library}/views/blocks/{:template}.{:type}.php', $appConfig['path'] . '/views/blocks/{:template}.{:type}.php'));
                 $View = new View(array('paths' => $paths));
                 $string .= $View->render('all', $data, $elementOptions);
             }
         }
         if (isset($block['options']['wrapperId'])) {
             $string .= "\n\t" . '</div>';
         }
     }
     if ($options['wrapperId']) {
         $string .= '</div>';
     }
     $string .= "\n";
     return $string;
 }
Exemple #15
0
 /**
  * Renders an element.
  *
  * @param string $element
  * @param array $data
  * @return string Rendered HTML
  */
 public function render($element, array $data = [])
 {
     $view = new View($this->_context->view()->_config);
     return $view->render(['element' => $element], $data);
 }
Exemple #16
0
 public function forgotpassword()
 {
     if ($this->request->data) {
         if (stristr($_SERVER['HTTP_REFERER'], COMPANY_URL) === FALSE) {
             return $this->redirect('/login');
             exit;
         }
         $msg = "Password reset link sent to your email address!";
         $user = Users::find('first', array('conditions' => array('email' => $this->request->data['email']), 'fields' => array('_id')));
         $email = $user['email'];
         //		print_r($user['_id']);
         $details = Details::find('first', array('conditions' => array('user_id' => (string) $user['_id']), 'fields' => array('key')));
         //					print_r($details['key']);exit;
         $key = $details['key'];
         if ($key != "") {
             $email = $this->request->data['email'];
             $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
             $body = $view->render('template', compact('email', 'key'), array('controller' => 'users', 'template' => 'forgot', 'type' => 'mail', 'layout' => false));
             $transport = Swift_MailTransport::newInstance();
             $mailer = Swift_Mailer::newInstance($transport);
             $message = Swift_Message::newInstance();
             $message->setSubject("Password reset link from " . COMPANY_URL);
             $message->setFrom(array(NOREPLY => 'Password reset email ' . COMPANY_URL));
             $message->setTo($email);
             $message->addBcc(MAIL_1);
             $message->addBcc(MAIL_2);
             $message->addBcc(MAIL_3);
             $message->setBody($body, 'text/html');
             $mailer->send($message);
         }
     }
     return compact('msg');
 }
 public function say($code)
 {
     $newcode = '';
     for ($i = 0; $i <= strlen($code); $i++) {
         $newcode = $newcode . substr($code, $i, 1) . ',,,,,';
     }
     $layout = false;
     $view = new View(array('paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     echo $view->render('all', compact('newcode'), array('controller' => 'ex', 'template' => 'say', 'type' => 'xml', 'layout' => 'default'));
     return $this->render(array('layout' => false));
     exit;
     //<Response>
     //	<Say>Please enter GreenCoinX mobile phone verification code.
     //	I repeat 3,4,5,6,9,1.
     //	Again. 3,4,5,6,9,1.</Say>
     //</Response>
 }
Exemple #18
0
 public function render($process, array $data = array(), array $options = array())
 {
     $defaults = array('theme' => 'default');
     $options += $defaults;
     return parent::render($process, $data, $options);
 }
 public function show()
 {
     $View = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php'), 'request' => $this->request));
     echo $View->render($this->request->params['type'], array(), array('template' => $this->request->params['name']));
     die;
 }
 public function testElementRenderingOptions()
 {
     $tmpDir = realpath(Libraries::get(true, 'resources') . '/tmp');
     $this->skipIf(!is_writable($tmpDir), "Can't write to resources directory.");
     $testApp = $tmpDir . '/tests/test_app';
     $viewDir = $testApp . '/views';
     mkdir($viewDir, 0777, true);
     Libraries::add('test_app', array('path' => $testApp));
     $body = '<?php echo isset($this->_options[$option]) ? $this->_options[$option] : ""; ?>';
     $template = $viewDir . '/template.html.php';
     file_put_contents($template, $body);
     $view = new View(array('paths' => array('template' => '{:library}/views/{:template}.html.php', 'layout' => false)));
     $options = array('template' => 'template', 'library' => 'test_app');
     $result = $view->render('all', array('option' => 'custom'), $options);
     $this->assertIdentical('', $result);
     $result = $view->render('all', array('option' => 'library'), $options);
     $this->assertIdentical('test_app', $result);
     $options = array('template' => 'template', 'library' => 'test_app', 'custom' => 'custom option');
     $result = $view->render('all', array('option' => 'custom'), $options);
     $this->assertIdentical('custom option', $result);
     $result = $view->render('all', array('option' => 'library'), $options);
     $this->assertIdentical('test_app', $result);
     Libraries::remove('test_app');
     $this->_cleanUp();
 }
Exemple #21
0
<?php

use lithium\action\Dispatcher;
use lithium\template\View;
use lithium\core\Libraries;
use lithium\net\http\Router;
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
    $result = $chain->next($self, $params, $chain);
    return $result;
});
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
    $result = $chain->next($self, $params, $chain);
    return $result;
});
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    $result = $chain->next($self, $params, $chain);
    $li3_show = Libraries::get('li3_show');
    $View = new View(array('paths' => array('template' => $li3_show['path'] . '/views/index.html.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
    $Show_SQL_View = $View->render('all', array($GLOBALS['Show_SQL']));
    if (!isset($result->body[0])) {
        $result = $Show_SQL_View . $result;
    } else {
        $result->body[0] = $Show_SQL_View . $result->body[0];
    }
    return $result;
});
Exemple #22
0
 public function addcompany()
 {
     $user = Session::read('default');
     $user_id = $user['_id'];
     if ($user == "") {
         return $this->redirect('/login');
     }
     if ($this->request->data) {
         $details = Details::find('first', array('conditions' => array('user_id' => $user_id)));
         if ($details['company']['verified'] == "Yes") {
             $data['company']['ShortName'] = $details['company']['ShortName'];
             $data['company']['verified'] = 'Yes';
         } else {
             $data['company']['ShortName'] = $this->request->data['ShortName'];
             $data['company']['verified'] = 'No';
         }
         $data['company']['Name'] = $this->request->data['Name'];
         $data['company']['Address'] = $this->request->data['Address'];
         $data['company']['Country'] = $this->request->data['Country'];
         $data['company']['Registration'] = $this->request->data['Registration'];
         $data['company']['GovernmentURL'] = $this->request->data['GovernmentURL'];
         $data['company']['TotalShares'] = (int) $this->request->data['TotalShares'];
         for ($i = 0; $i < 10; $i++) {
             $data['company']['share'][$i] = (int) $this->request->data['share'][$i];
             $data['company']['price'][$i] = (double) $this->request->data['price'][$i];
             $data['company']['sold'][$i] = (int) $this->request->data['sold'][$i];
         }
         $data['company']['id'] = new MongoID();
         Details::find('all', array('conditions' => array('user_id' => $user_id)))->save($data);
         $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
         $email = $user['email'];
         $body = $view->render('template', compact('data', 'user'), array('controller' => 'users', 'template' => 'addcompany', 'type' => 'mail', 'layout' => false));
         $transport = Swift_MailTransport::newInstance();
         $mailer = Swift_Mailer::newInstance($transport);
         $message = Swift_Message::newInstance();
         $message->setSubject("Company Registered with " . COMPANY_URL);
         $message->setFrom(array(NOREPLY => 'Company Registered with ' . COMPANY_URL));
         $message->setTo($email);
         $message->setBody($body, 'text/html');
         $mailer->send($message);
     }
     $details = Details::find('first', array('conditions' => array('user_id' => $user_id)));
     return compact('details');
 }
Exemple #23
0
 public function testContextWithElementRenderingOptions()
 {
     $tmpDir = realpath(Libraries::get(true, 'resources') . '/tmp');
     $this->skipIf(!is_writable($tmpDir), "Can't write to resources directory.");
     $testApp = $tmpDir . '/tests/test_app';
     $viewDir = $testApp . '/views';
     mkdir($viewDir . '/elements', 0777, true);
     Libraries::add('test_app', array('path' => $testApp));
     $testApp2 = $tmpDir . '/tests/test_app2';
     $viewDir2 = $testApp2 . '/views';
     mkdir($viewDir2 . '/elements', 0777, true);
     Libraries::add('test_app2', array('path' => $testApp2));
     $body = "<?php ";
     $body .= "echo \$this->_render('element', 'element2', array(), ";
     $body .= "array('library' => 'test_app2'));";
     $body .= "echo \$this->_render('element', 'element1');";
     $body .= "?>";
     file_put_contents($viewDir . '/template.html.php', $body);
     file_put_contents($viewDir . '/elements/element1.html.php', 'element1');
     file_put_contents($viewDir2 . '/elements/element2.html.php', 'element2');
     $view = new View(array('compile' => false, 'paths' => array('template' => '{:library}/views/{:template}.html.php', 'element' => '{:library}/views/elements/{:template}.html.php', 'layout' => false)));
     $options = array('template' => 'template', 'library' => 'test_app');
     $result = $view->render('all', array(), $options);
     $this->assertIdentical('element2element1', $result);
     $body = "<?php ";
     $body .= "echo \$this->_render('element', 'element1');";
     $body .= "echo \$this->_render('element', 'element2', array(), ";
     $body .= "array('library' => 'test_app2'));";
     $body .= "?>";
     file_put_contents($viewDir . '/template.html.php', $body);
     $result = $view->render('all', array(), $options);
     $this->assertIdentical('element1element2', $result);
     Libraries::remove('test_app');
     Libraries::remove('test_app2');
     $this->_cleanUp();
 }
 public function SendEmails($order_id, $user_id)
 {
     $order = Orders::find('first', array('conditions' => array('_id' => new MongoID($order_id))));
     $user = Users::find('first', array('conditions' => array('_id' => new MongoID($user_id))));
     $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
     $body = $view->render('template', compact('order', 'user'), array('controller' => 'ex', 'template' => 'OrderRequest', 'type' => 'mail', 'layout' => false));
     $transport = Swift_MailTransport::newInstance();
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setSubject("Your order is placed");
     $message->setFrom(array(NOREPLY => 'Your order is placed'));
     $message->setTo($user['email']);
     //		$message->addBcc(MAIL_1);
     //		$message->addBcc(MAIL_2);
     //		$message->addBcc(MAIL_3);
     $message->setBody($body, 'text/html');
     $mailer->send($message);
 }
Exemple #25
0
 public function rejectwithdrawal($id = null, $reason = null)
 {
     if ($this->__init() == false) {
         $this->redirect('ex::dashboard');
     }
     $Authuser = Session::read('member');
     $AuthBy = $Authuser['username'];
     $reason = Reasons::find('first', array('conditions' => array('code' => $reason)));
     $data = array('Reason' => $reason['reason'], 'Approved' => 'Rejected', 'ApprovedBy' => $AuthBy);
     $Transactions = Transactions::find('first', array('conditions' => array('_id' => $id)))->save($data);
     $Transactions = Transactions::find('first', array('conditions' => array('_id' => $id)));
     $details = Details::find('first', array('conditions' => array('username' => $Transactions['username'])));
     $user = Users::find('first', array('conditions' => array('_id' => new MongoID($details['user_id']))));
     $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
     $body = $view->render('template', compact('Transactions', 'details', 'user'), array('controller' => 'admin', 'template' => 'rejectwithdrawal', 'type' => 'mail', 'layout' => false));
     $transport = Swift_MailTransport::newInstance();
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $message->setSubject("Withdrawal Rejected " . COMPANY_URL . ": " . $reason['reason']);
     $message->setFrom(array(NOREPLY => 'Withdrawal Rejected ' . COMPANY_URL . ": " . $reason['reason']));
     $message->setTo($user['email']);
     $message->addBcc(MAIL_1);
     $message->addBcc(MAIL_2);
     $message->addBcc(MAIL_3);
     $message->setBody($body, 'text/html');
     $mailer->send($message);
     $this->redirect('Admin::withdrawals');
 }
Exemple #26
0
 public function pdf($id = null)
 {
     $document = Documents::find('first', array('conditions' => array('hash' => $id)));
     if (count($document) == 0) {
         return $this->redirect('kyc::index');
         exit;
     }
     $image_passport_face = File::find('first', array('conditions' => array('details_passport_face_id' => (string) $document['_id'])));
     if ($image_passport_face['filename'] != "") {
         $imagename_passport_face = $image_passport_face['_id'] . '_' . $image_passport_face['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_passport_face;
         file_put_contents($path, $image_passport_face->file->getBytes());
     }
     $image_address = File::find('first', array('conditions' => array('details_address_id' => (string) $document['_id'])));
     if ($image_address['filename'] != "") {
         $imagename_address = $image_address['_id'] . '_' . $image_address['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_address;
         file_put_contents($path, $image_address->file->getBytes());
     }
     $image_passport = File::find('first', array('conditions' => array('details_passport_id' => (string) $document['_id'])));
     if ($image_passport['filename'] != "") {
         $imagename_passport = $image_passport['_id'] . '_' . $image_passport['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_passport;
         file_put_contents($path, $image_passport->file->getBytes());
     }
     $image_driving = File::find('first', array('conditions' => array('details_driving_id' => (string) $document['_id'])));
     if ($image_driving['filename'] != "") {
         $imagename_driving = $image_driving['_id'] . '_' . $image_driving['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_driving;
         file_put_contents($path, $image_driving->file->getBytes());
     }
     $image_tax = File::find('first', array('conditions' => array('details_tax_id' => (string) $document['_id'])));
     if ($image_tax['filename'] != "") {
         $imagename_tax = $image_tax['_id'] . '_' . $image_tax['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_tax;
         file_put_contents($path, $image_tax->file->getBytes());
     }
     $printdata = $document;
     $imagedata = array('image_passport' => $imagename_passport, 'image_driving' => $imagename_driving, 'image_tax' => $imagename_tax, 'image_address' => $imagename_address, 'image_passport_face' => $imagename_passport_face);
     $view = new View(array('paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     echo $view->render('all', compact('printdata', 'imagedata'), array('controller' => 'print', 'template' => 'kyc', 'type' => 'pdf', 'layout' => 'printkyc'));
     return "/webroot/qrcode/KYC-XGCWallet-" . $document['kyc_id'] . "-X.pdf";
 }