Skip to content

Commit 58e01a6

Browse files
committed
New Textile compiler and SlyP core
1 parent 0d4727f commit 58e01a6

21 files changed

+6198
-967
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11

2-
/.sass-cache
2+
/.sass-cache
3+
/articulos/cached
4+
5+
# Do not ignore these files...
6+
/articulos/cached/.htaccess

SlypCore.php

+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
<?php
2+
3+
/*
4+
SlypCore
5+
6+
S L y P (Simple, Limpio y Potente / Simple, Lean y Potent)
7+
8+
MIT License
9+
===========
10+
11+
Copyright (c) 2012 Agustin Amenabar <[email protected]>
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a
14+
copy of this software and associated documentation files (the "Software"),
15+
to deal in the Software without restriction, including without limitation
16+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+
and/or sell copies of the Software, and to permit persons to whom the
18+
Software is furnished to do so, subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included in
21+
all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29+
DEALINGS IN THE SOFTWARE.
30+
*/
31+
class SlypCore{
32+
33+
protected $_errors=array();
34+
protected $acctions=array();
35+
protected $mailWebmaster = '[email protected]';
36+
protected $nombreMarca = 'Code Blog Médula';
37+
protected $mailAministrador = '[email protected]';
38+
protected $_templateDir = '';
39+
protected $_cachedHtml = './articulos/cached/';
40+
protected $articleList;
41+
const noventa = 7776000;
42+
const treinta = 2592000;
43+
44+
function __construct()
45+
{
46+
require "inc/libs/classTextile.php";
47+
require "inc/libs/markdown.php";
48+
require "inc/libs/simple_html_dom.php";
49+
}
50+
51+
public function getArticleList(){
52+
if( !count( $this->articleList ) ){
53+
$this->loadArticleList();
54+
}
55+
return $this->articleList;
56+
}
57+
58+
function getArticle($filename){
59+
//$this->processContents();
60+
//print_r($this->articleList);
61+
$ao = new stdClass();
62+
$arl = $this->getArticleList();
63+
foreach ($arl as $onea) {
64+
if( $onea['filename'] == $filename ){
65+
foreach ($onea as $key => $value) {
66+
$ao->{$key} = $value;
67+
}
68+
break;
69+
}
70+
}
71+
if (!isset($ao->modDate)) {
72+
$this->_errors['5']=true;
73+
return false;
74+
}
75+
$ao->path = $this->_cachedHtml.($filename).$ao->modDate.'.html';
76+
if(!is_file($ao->path))echo 'NO ENCUENTRO: '.$ao->path;
77+
//var_dump($ao);
78+
return $ao;
79+
}
80+
81+
public function getTemplateFile($bname){
82+
if( is_file( $this->_templateDir . $bname) )return $this->_templateDir . $bname;
83+
if( is_file( $this->_templateDir . $bname . '.php') )return $this->_templateDir . $bname . '.php';
84+
if( is_file( $this->_templateDir . $bname . '.html') )return $this->_templateDir . $bname . '.html';
85+
return '';
86+
}
87+
88+
public function processContents($forceRewrite=false){
89+
$fileList = $this->getFileList();
90+
$this->articleList = array();
91+
foreach ($fileList as $oneArticle) {
92+
$leyendoEncabezados = true;
93+
$articleRawFile = "./articulos/".$oneArticle['filename'];
94+
$articleRawFilesize = filesize( $articleRawFile );
95+
$fhandl = fopen($articleRawFile, 'r+b');
96+
$lastpos = 0;
97+
while (($buffer = fgets($fhandl)) !== false) {
98+
//echo "\nbuff=".trim($buffer).';';
99+
if(!trim($buffer)){
100+
if( !isset($oneArticle['pubDate']) ){//si el artículo no tiene fecha de publicación guardada, guardamos la última modificación como fecha de publicación
101+
$oneArticle['pubDate'] = date('Y-m-d H:i:s',$oneArticle['modDate']);
102+
$agregado = 'pubDate:'.$oneArticle['pubDate'].PHP_EOL.PHP_EOL;
103+
$theRest = fread($fhandl, $articleRawFilesize);
104+
fseek($fhandl, $lastpos);
105+
fwrite($fhandl, $agregado.$theRest);
106+
$articleRawFilesize += strlen($agregado);
107+
fseek($fhandl, $lastpos);
108+
//$leyendoEncabezados=false;
109+
continue;
110+
}
111+
$leyendoEncabezados=false;
112+
break;
113+
}
114+
$lastpos = ftell($fhandl);
115+
$posDivisor = strpos($buffer, ':');
116+
if($posDivisor===false)$posDivisor = strlen( $buffer );
117+
$key = substr($buffer, 0, $posDivisor);
118+
$value = substr($buffer, $posDivisor+1);
119+
//echo "\n".trim($key).'=>'.trim($value)." ".$oneArticle.' '.$oneArticle['filename'];
120+
if( strtolower( trim( $key ) ) == 'not_article' )continue;
121+
$oneArticle[trim($key)] = trim($value);
122+
}
123+
if(!$leyendoEncabezados){//ya leímos los encabezados ahora, procesamos el cuerpo de texto.
124+
$articleCachedUrl = $this->_cachedHtml.$oneArticle['filename'].$oneArticle['modDate'].'.html';
125+
//if( true ){
126+
if( !is_file( $articleCachedUrl ) || $forceRewrite ){
127+
$articleRawText = fread( $fhandl, $articleRawFilesize );
128+
if(!$articleRawText)$articleRawText = 'ERROR: no file could be read by fread.';
129+
if(!isset($oneArticle['markdown'])){
130+
$textile = new Textile('html5');
131+
$articleHtml = $textile->TextileThis($articleRawText);
132+
}else{
133+
$articleHtml = Markdown($articleRawText);
134+
}
135+
$articleDom = str_get_html($articleHtml);
136+
$introParagraph = $articleDom->find('.intro',0);
137+
if($introParagraph === null)$introParagraph = $articleDom->find('p',0);
138+
if($introParagraph !== null){
139+
$oneArticle['intro'] = trim( $introParagraph->innertext );
140+
}
141+
}
142+
if( @file_put_contents( $articleCachedUrl, $articleHtml ) ){
143+
$this->_errors['2']=true;
144+
}
145+
146+
}
147+
$this->articleList[] = $oneArticle;
148+
fclose($fhandl);
149+
}
150+
//benchmarkUnserialization($this->articleList);
151+
//print_r($this->articleList);
152+
usort($this->articleList, function($a, $b) {
153+
return $b['pubDate'] - $a['pubDate'];
154+
});
155+
if( @file_put_contents( $this->_cachedHtml.'contents.enc', serialize($this->articleList) ) === false)$this->_errors['3'] = true;
156+
return $this->articleList;
157+
}
158+
159+
private function getFileList(){
160+
$directory = new DirectoryIterator("./articulos");
161+
$fileList = Array();
162+
foreach ($directory as $fileinfo) {
163+
if ($fileinfo->isFile()) {
164+
$extension = pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION);
165+
//echo "<br>". $fileinfo->getFilename() . ' -> ' . $extension;
166+
if(strtolower($extension) === 'txt'){
167+
$oneArticle = array(
168+
'filename' => $fileinfo->getFilename(),
169+
'modDate' => $fileinfo->getMTime()
170+
);
171+
$fileList[]=$oneArticle;
172+
}
173+
}
174+
}
175+
return $fileList;
176+
}
177+
178+
protected function loadArticleList(){
179+
$encodedFileList = $this->_cachedHtml.'contents.enc';
180+
if( is_file( $encodedFileList ) ){
181+
$unserializedT = @unserialize( file_get_contents( $encodedFileList ) );
182+
if( $unserializedT === false)$this->_errors['4'] = true;
183+
$this->articleList = $unserializedT;
184+
}else{
185+
$this->processContents();
186+
}
187+
}
188+
189+
protected function activaAcciones(){
190+
$algunaActivada=false;
191+
if(isset($_GET['a'])&& $_GET['a'] && isset($this->acciones[$_GET['a']])){
192+
$this->{$this->acciones[$_GET['a']]}();
193+
$algunaActivada=true;
194+
}
195+
return $algunaActivada;
196+
}
197+
198+
protected function avisaWebmaster($message=''){
199+
$message.="\r\n\r\nen la fecha:".date('Y-m-d H:i:s');
200+
$message.="\r\n\r\nen el archivo:".$_SERVER['PHP_SELF']."\r\nllamdo en:".$_SERVER['REQUEST_URI'];
201+
$this->$mailWebmaster;
202+
$this->$nombreMarca;
203+
$this->$mailAministrador;
204+
$to = $mailWebmaster;
205+
$subject = 'Error en sitio'.$nombreMarca;
206+
$additionalHeaders = "From: Soporte $nombreMarca <".$mailAministrador.">\n";
207+
$additionalHeaders .= 'MIME-Version: 1.0' . "\n";
208+
$additionalHeaders .= 'Content-type: text/plain; charset=utf-8' . "\n";
209+
@mail($to, $subject,$message,$additionalHeaders);
210+
}
211+
212+
protected function valida_email($email) {
213+
if (preg_match("/[\\000-\\037]/",$email)) {
214+
return false;
215+
}
216+
$pattern = "/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD";
217+
if(!preg_match($pattern, $email)){
218+
return false;
219+
}
220+
return true;
221+
}
222+
223+
public function benchmarkUnserialization($toSer){
224+
$enJson = json_encode($toSer);
225+
$enPhp = serialize($toSer);
226+
227+
//***************** JSON
228+
$beforeJson = microtime(true);
229+
230+
for ($i=0; $i < 100000 ; $i++) {
231+
json_decode($enJson);
232+
}
233+
234+
$afterJson = microtime(true);
235+
echo ($afterJson-$beforeJson) . " sec/json_decode\n";
236+
237+
//***************** UNSERIALIZE
238+
$beforePhp = microtime(true);
239+
240+
for ($i=0; $i < 100000 ; $i++) {
241+
unserialize($enPhp);
242+
}
243+
244+
$afterPhp = microtime(true);
245+
echo ($afterPhp-$beforePhp) . " sec/unserialize\n";
246+
}
247+
248+
public function getError($nombre=false){
249+
if($nombre===false){
250+
return (bool) count($this->_errors);
251+
}else{
252+
if(!isset($this->_errors[$nombre]))return false;
253+
return (bool) $this->_errors[$nombre];
254+
}
255+
return false;
256+
}
257+
}
258+
259+
260+
261+
262+
?>

SlypMore.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
function getMostRecent($list,$limit=5){
3+
usort($list, function($a, $b) {
4+
return $b['modDate'] - $a['modDate'];
5+
});
6+
return array_splice($list, 0, $limit);
7+
}
8+
?>

article.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!doctype html>
2+
<!--[if lt IE 7]>
3+
<html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en">
4+
<![endif]-->
5+
<!--[if IE 7]>
6+
<html class="no-js lt-ie9 lt-ie8" lang="en">
7+
<![endif]-->
8+
<!--[if IE 8]>
9+
<html class="no-js lt-ie9" lang="en">
10+
<![endif]-->
11+
<!--[if gt IE 8]>
12+
<!-->
13+
<html class="no-js" lang="en">
14+
<!--<![endif]-->
15+
<head>
16+
<meta charset="utf-8">
17+
18+
<title><?php echo $theArticle->title; ?>Code Médula &ndash; Blog de código</title>
19+
<?php if (isset($theArticle->subtitle)): ?>
20+
<meta name="description" content="<?php echo $theArticle->subtitle; ?>">
21+
<?php endif ?>
22+
<meta name="author" content="B. Agustín Amenabar L.">
23+
24+
<meta name="viewport" content="width=device-width">
25+
26+
<link rel="stylesheet" href="css/styles.css">
27+
28+
<script src="js/libs/modernizr-2.5.3-respond-1.1.0.min.js"></script>
29+
</head>
30+
<body>
31+
<!--[if lt IE 7]>
32+
<p class=chromeframe>
33+
Your browser is <em>ancient!</em>
34+
<a href="http://browsehappy.com/">Upgrade to a different browser</a>
35+
or
36+
<a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a>
37+
to experience this site.
38+
</p>
39+
<![endif]-->
40+
41+
<div class="mainContainer">
42+
<header class="contiene-logo">
43+
<img src="img/content/logo-blog-medula-code.png" alt="Logotipo Médula Diseño Code Blog"></header><article>
44+
<?php require $theArticle->path; ?>
45+
<footer>
46+
<?php if ( isset($theArticle->tags) && $theArticle->tags ): ?>
47+
<h2>Tags: <?php echo $theArticle->tags; ?></h2>
48+
<?php endif ?>
49+
<h2>Comments</h2>
50+
<div id="disqus_thread"></div>
51+
<script type="text/javascript">
52+
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
53+
var disqus_shortname = 'codeblogmedula'; // required: replace example with your forum shortname
54+
55+
/* * * DON'T EDIT BELOW THIS LINE * * */
56+
(function() {
57+
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
58+
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
59+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
60+
})();
61+
</script>
62+
<noscript>
63+
Please enable JavaScript to view the
64+
<a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a>
65+
</noscript>
66+
<a href="http://disqus.com" class="dsq-brlink">
67+
comments powered by
68+
<span class="logo-disqus">Disqus</span>
69+
</a>
70+
</footer>
71+
</article><?php include "inc/template/aside-gral.php"; ?>
72+
73+
</div>
74+
<!-- #main -->
75+
</div>
76+
<!-- #main-container -->
77+
78+
<div id="footer-container">
79+
<footer class="wrapper">
80+
<h3>footer</h3>
81+
</footer>
82+
</div>
83+
84+
<script type="text/javascript" src="http://use.typekit.com/zod4yoy.js"></script>
85+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
86+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
87+
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>
88+
89+
<script src="js/script.js"></script>
90+
<script>
91+
/* var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
92+
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
93+
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
94+
s.parentNode.insertBefore(g,s)}(document,'script'));*/
95+
</script>
96+
97+
</body>
98+
</html>

0 commit comments

Comments
 (0)