Jump to content

Awilum

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by Awilum

  1. Hi ! Thanks for your feedback! I will check all your mentioned points and will fix them. About template engine. Fenom is not very popular now, but it has big potential, I think. Fenom is super fast and lightweight, its syntax is similar to Smarty and they have a fallback class for smarty templates. Fenom Repository: https://github.com/fenom-template/fenom Fenom Benchmark: https://github.com/fenom-template/fenom/blob/master/docs/en/benchmark.md
  2. Hello) I created Morfy and site for it: http://morfy.org Website homepage screenshot:
  3. Hello) I created Monstra CMS and site for it: http://monstra.org
  4. I write for example class Text: class Text { public static function test() { return 'test text'; } } Today I found this code: class Text { /** * Protected constructor since this is a static class. * * @access protected */ protected function __construct(){ // Nothing here } public static function test() { return 'test text'; } } How much appropriate is to write this? /** * Protected constructor since this is a static class. * * @access protected */ protected function __construct(){ // Nothing here }
  5. Yes, I tried to make this script with XML Parser, but difficult to recreate such a parser that I need. I need to recreate all the keys, plus embedded design elements with the same name. <?php set_time_limit(0); /*$mongo = new Mongo(); $tess = $mongo->selectDB('tess');*/ $case = array(); global $case; class SaxClass { private $serial_number = false; private $registration_number = false; private $mark_identification = false; private $status_date = false; private $filing_date = false; private $published_for_opposition_date = false; private $state = false; private $p = false; /** * Callback for the start of each element */ function startElement($parser_object, $elementname, $attribute) { global $case; if ($elementname == "serial-number") $this->serial_number = true; else $this->serial_number = false; if ($elementname == "registration-number") $this->registration_number = true; else $this->registration_number = false; if ($elementname == "mark-identification") $this->mark_identification = true; else $this->mark_identification = false; if ($elementname == "status-date") $this->status_date = true; else $this->status_date = false; if ($elementname == "filing-date") $this->filing_date = true; else $this->filing_date = false; if ($elementname == "published-for-opposition-date") $this->published_for_opposition_date = true; else $this->published_for_opposition_date = false; if ($elementname == "nationality") { $this->p = true; } else { $this->p = false; } if($this->p == true && $elementname == 'state') { $this->state = true; } else { $this->state = false; } if ($elementname == "case-file") { echo 'start' . "\n"; $case = array(); } } /** * Callback for the end of each element */ function endElement($parser_object, $elementname) { global $tess, $case; if ($elementname == "case-file") { print_r($case); //$tess->case_file_spc->insert($case); echo 'end' . "\n"; } } /** * Callback for the content within an element */ function contentHandler($parser_object, $data) { global $tess, $case; if ($this->serial_number) if($this->cl($data) !== '') $case['serial-number'] = $this->cl($data); if ($this->registration_number) if($this->cl($data) !== '') $case['registration-number'] = $this->cl($data); if ($this->mark_identification) if($this->cl($data) !== '') $case['mark-identification'] = $this->cl($data); if ($this->status_date) if($this->cl($data) !== '') $case['status-date'] = $this->cl($data); if ($this->filing_date) if($this->cl($data) !== '') $case['filing-date'] = $this->cl($data); if ($this->published_for_opposition_date) if($this->cl($data) !== '') $case['published-for-opposition-date'] = $this->cl($data); if ($this->state) if($this->cl($data) !== '') $case['state'] = $this->cl($data); } /** * Clean text */ function cl($data) { return preg_replace('/^\\s+|\\s+$/m', '', $data); } } /** * Function to start the parsing once all values are set and * the file has been opened */ function doParse($parser_object) { if(!($fp = fopen("small.xml", "r"))); //loop through data while ($data = fread($fp, 4096)) { //parse the fragment xml_parse($parser_object, $data, feof($fp)); } } $SaxObject = new SaxClass(); $parser_object = xml_parser_create(); xml_set_object($parser_object, $SaxObject); //Don't alter the case of the data xml_parser_set_option($parser_object, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($parser_object, "startElement", "endElement"); xml_set_character_data_handler($parser_object, "contentHandler"); doParse($parser_object); does not work, this condition if ($elementname == "nationality") { $this->p = true; } else { $this->p = false; } if($this->p == true && $elementname == 'state') { $this->state = true; } else { $this->state = false; }
  6. gizmola YES I Know but why proccess php.exe is leak mush memory when i parse data... I dont why..
  7. http://commondatastorage.googleapis.com/trademarks/applications/2011/apc110101.zip http://www.google.com/googlebooks/uspto-trademarks-recent-applications.html
  8. xyph This makes XMLReader or you think not ? >fopen()/fgets()/fclose() I can not find / think of a solution as a line otherwise collect everything in between <case-file> </case-file>
  9. I rewrote the script. Frees memory as I can. For data storage use MongoDB. General problem that runs the memory remains. But this should not be with XMLReader i think. xmlreader.php <?php $start_time = microtime(true); include 'inc/Misc.php'; logAdd('Script start'); set_time_limit(0); // Try to enable garbage collection on 5.3+ if (function_exists('gc_enable') && !gc_enabled()) { gc_enable(); } //$mongo = new Mongo(); $db = 'tess'; $collection = 'apc'; $files = array(/*'xml/apc101231-42.xml',*/ /*'xml/apc110101.xml'*/ 'xml/apc110101.xml'); foreach($files as $file) { echo "\n"; echo 'Filename: '.basename($file)."\n"; echo 'Start parsing...'."\n"; echo "\n"; $reader = new XMLReader(); $reader->open($file); logAdd('Srart parsing'); while ($reader->read()) { switch ($reader->nodeType) { case (XMLREADER::ELEMENT): if ($reader->localName == "case-file") { logAdd('case-file found'); $dom = new DomDocument(); $n = $dom->importNode($reader->expand(),true); $dom->appendChild($n); $sxe = simplexml_import_dom($n); logAdd('case-file in $sxe'); // Insert data! //$mongo->$db->$collection->insert($sxe); logAdd('Insert done!'); //print_r($sxe); echo "Insert done! \n"; // Now clear the memory. unset($n, $dom, $sxe); logAdd('Clear the memory'); } break; } logAdd('case-file in $sxe'); } // Close the resource $reader->close(); // Delete the object to free memory unset($reader); logAdd('Stop parsing'); } $mongo->close(); inc/Misc.php <?php /** * Convert bytes in 'kb','mb','gb','tb','pb' * @param integer $size Data to convert * @return string */ function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } /** * Get memory usage * @param boolean $render Displays the result of the function in the browser or not */ function getMemoryUsage($render=true) { if (function_exists('memory_get_usage')) { $memory_usage = memory_get_usage(); } else if (substr(PHP_OS,0,3) == 'WIN') { // Windows 2000 workaround $output = array(); exec('pslist ' . getmypid() , $output); $memory_usage = trim(substr($output[8],38,10)); } else { $memory_usage = ''; } if($render) { printf('Memory usage: '.convert($memory_usage)); } else { return $memory_usage; } } /** * Get elapsed time * @global integer $start_time Start time value * @param boolean $render Displays the result of the function in the browser or not */ function getElapsedTime($render=true) { global $start_time; $result_time = microtime(true) - $start_time; if($render) printf("Elapsed time %.3f seconds",$result_time); else return sprintf("%.3f", $result_time); } /** * Benchmark */ function benchmark() { getMemoryUsage(); echo " - "; getElapsedTime(); echo "\n"; } /** * Log add */ function logAdd($message) { file_put_contents('log.txt',$message.' - '.convert(getMemoryUsage(false))." - ".getElapsedTime(false)."\n", FILE_APPEND); } ?> Log I do not see any problems, but the process memory leak my script have.
  10. I need to parse large XML files ranging in size from ~ 500 to ~ 1700 Mb. I use XMLReader set_time_limit(0); $start_time = microtime(true); include_once 'inc/Misc.php'; include_once 'inc/Database.php'; $files = array('xml/large_file.xml'); foreach($files as $file) { echo "\n"; echo 'Filename: '.basename($file)."\n"; echo 'Filesize: '.convert(filesize($file))."\n"; echo 'Start parsing...'."\n"; echo "\n"; $reader = new XMLReader(); $reader->open($file); while ($reader->read()) { switch ($reader->nodeType) { case (XMLREADER::ELEMENT): if ($reader->localName == "element-name") { $dom = new DomDocument(); $n = $dom->importNode($reader->expand(),true); $dom->appendChild($n); $sxe = simplexml_import_dom($n); $tess->file_big->insert($sxe); echo "Insert done! "; benchmark(); } } } } Everything is fine in the beginning ... Parsed file and slowly inserted my desired data, but is gradually growing memory consumption and has run out of resources. That is, I took the file to 400 Mb and as long as it is spent parsing of 2000 Mb of RAM and all the resources ran out and the script is stopped. How to deal with large files? ~ 500 to ~ 1700 Mb. Will there XML Parser? Yes, and how to apply it to my problem? Another option could have?
  11. Popcorn as a template engine in CodeIgniter 1) Download Popcorn Template Engine(http://popcorn.template-cms.org) and extract into \application\libraries\ 2) Download Templates.zip and extract into \application\libraries\ Example: 3) Create folder for comiled templates \templates_c\ in the root 4) In the controller load the library. $this->load->library('templates'); 5) Use Popcorn Template Engine $this->templates->assign('msg','Hello CI !'); $this->templates->draw('welcome_message');
  12. Snippets for Sublime Text @@ - {@ $var} @echo - {echo $var} @if - {if $var} {/if} @ifelse - {if $var} {else} {/if} @ifelseif - {if $var} {elseif $var} {/if} @loop - {loop $key as $item} {/loop} @var - {var name $var2} @const - {const name $value} @assign - {assign var $value} @include - {include 'template_name'} @file - {file 'filename'} @run - {run function()} @vars - {vars} @codes - {codes} @dump - {dump $var} Download: popcorn.zip Install: Unpack the archive to a folder Sublime Text\Packages\User
  13. ignace >Never wrote XHTML? You do know XML and XSLT, do you? I think we talking about Designers or not ?)) >You do know... Yes, but the designers do not!
  14. I just looked at a simple example phptal and does not understand anything Оо <div class="item" tal:repeat="item itemsArray"> <span tal:condition="item/hasDate" tal:replace="item/getDate"/> <a href="${item/getUrl}" tal:content="item/getTitle"/> <p tal:content="value/getContent"/> </div>
  15. ignace yes I know that I must do some think with long echo {echo $language} ....
  16. ignace >A template engine is to assist designers in creating the templates without having to learn PHP or anything complex hm... I think php programmer will learn Popcorn faster than Smarty. Because syntax like in php and smarty. Yes. php programmers also use template engines. php - TEMPLATE ENGINE --------------------------------------- <ul> <?php if(isset($languages) && is_array($languages) && sizeof($languages)) foreach($languages as $language) { ?> <li><?php echo $language; ?></li> <?php } ?> </ul> Smarty --------------------------------------- <ul> {foreach from=$languages item=language} <li>{$language}</li> {/foreach} </ul> Popcorn --------------------------------------- <ul> {loop $languages as $language} <li>{echo $language}</li> {/loop} </ul> I do not see any problems for designers)
  17. ignace http://www.smarty.net/docsv2/en/ - No creating variables in template or including ? And i think that this tags will be also helpful {vars} {dump $var} may not be for a designer course. And so the basic syntax for templates is in the Popcorn.
  18. Hello ) I wrote this simple template engine for PHP! Popcorn! Site: http://popcorn.template-cms.org/ Built-in popcorn template codes {echo $var} - Output variable {var name $var2} - Assign local template variable {const name $value} - Assign constant {file 'filename'} - Load file {run function()} - Run php function {if expr} {else} {elseif expr} {/if}- If construct {loop $mas as $item}{/loop} {loop $mas as $key => $item}{/loop} - Loop construct {codes} - Show all declared template codes {vars} - Show all declared variables {dump $var} - Dumps information about a variable {assign var 'value'} or {assign var $value} - Assign global variable {include 'template_name'} - Include other template Simple php application <?php // Include Popcorn include 'popcorn/popcorn.class.php'; // Initialize a Popcorn object $popcorn = new Popcorn(); // Variable assign $variable = 'Hello World!'; $popcorn->assign('variable',$variable); $popcorn->assign('show',true); // Draw the template $popcorn->draw('page'); ?> Simple template <html> <head> <title>Simple template</title> </head> <body> {if $show} {echo $variable} {/if} </body> </html> p.s. TCodes - closed!
  19. I wrote this simple template engine for PHP! Simple php application <?php // Include TCodes include 'tcodes/TCodes.php'; // Add new tcode addTCode('message','Hello world!'); // Adding Dynamic Data $vars['admin'] = true; $vars['username'] = 'Username'; // Loading a Template template('templates/page.php',$vars); ?> Simple template <html> <head> <title>Simple template</title> </head> <body> {if:$admin} {echo:$username} {end} <p>{message}</p> </body> </html> Site: http://tcodes.template-cms.org/
  20. Hello) This is my english site about Template CMS http://template-cms.org/
  21. Is it possible to get something as a reference in the script if it is such a http://site.com/home#p1 tried in different ways but #p1 my script does not see
  22. I wrote wrong LDAP server for test but my script dont die! why ? in php.ini I wrote extension=php_ldap.dll and I have this lib in php/ext/ error_reporting(1); $ldaphost = 'my.office.company.com'; // Connecting to LDAP $ip = gethostbyname($ldaphost); $ldapconn = ldap_connect($ip) or die("Could not connect to $ldaphost"); echo 'done';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.