Open Sencillo  2015.107
Long live the simplicity of PHP
 All Data Structures Namespaces Functions Pages
core_functions.php
1 <?php
12 {
13  public $name;
14 
15  private $rfp;
16  private $wfp;
17  private $contents;
18 
23  public function __construct($name)
24  {
25  $this->name = $name;
26  }
31  final public function write($data)
32  {
33  $this->wfp = fopen($this->name,"wb");
34  fwrite($this->wfp,$data);
35  fclose($this->wfp);
36  }
41  final public function read()
42  {
43  $this->rfp = fopen($this->name,"rb");
44  $this->contents = '';
45  while (!feof($this->rfp))
46  {
47  $this->contents .= fread($this->rfp, 8192);
48  }
49  fclose($this->rfp);
50  return $this->contents;
51  }
52 }
62 class file extends fileSystem
63 {
68  public function __construct($name)
69  {
70  chmod("../fw_core/", 0777);
71  chmod("../fw_cache/", 0777);
72  chmod("../fw_headers/", 0777);
73  chmod("../fw_modules/", 0777);
74  chmod("../fw_libraries/", 0777);
75  chmod("../fw_script/", 0777);
76  chmod("../", 0777);
77  }
82  public function __destruct()
83  {
84  chmod("../fw_core/", 0700);
85  chmod("../fw_cache/", 0700);
86  chmod("../fw_headers/", 0700);
87  chmod("../fw_modules/", 0700);
88  chmod("../fw_libraries/", 0700);
89  chmod("../fw_script/", 0700);
90  chmod("../", 0700);
91  }
92 }
103 {
104  public $seo;
105  public $info;
106 
107  private $header;
108  private $body;
109  private $lang;
110  private $oginfo;
111 
115  public function __construct()
116  {
117  $this->header['doctype-def']='<!DOCTYPE html>';
118  $this->header['html-def']='<html><head>';
119  $this->body='</head>';
120  }
121 
126  public function keywords($kw)
127  {
128  $this->header['keywords-def'] = '<meta name="keywords" content="'.$kw.'" />';
129  }
130 
135  public function encode($ec='UTF-8')
136  {
137  $this->header['charset-def'] = '<meta charset="'.$ec.'" />';
138  }
139 
143  public function responsive()
144  {
145  $this->header['responsive-def'] = '<meta name="viewport" content="width=device-width, initial-scale=1">';
146  }
147 
152  public function title($t)
153  {
154  if(strlen($t)>69)
155  {
156  $t = substr($t,0,66).'...';
157  }
158  $this->header['title-def'] = '<title>'.$t.'</title>';
159  $this->oginfo['title'] = $t;
160  }
161 
166  public function description($data)
167  {
168  if(strlen($data)>159)
169  {
170  $data = substr($data,0,155).'...';
171  }
172  $this->header['description-def'] = '<meta name="description" content="'.$data.'">';
173  $this->oginfo['description'] = $data;
174  }
175 
179  public function robots()
180  {
181  $this->header['robots-def'] = '<meta name="ROBOTS" content="NOODP"><meta name="Slurp" content="NOYDIR">';
182  }
183 
188  public function owner($author)
189  {
190  $this->header['owner-def'] = '<meta name="author" content="'.$author.'">';
191  }
192 
196  public function generator()
197  {
198  $this->header['generator-def'] = '<meta name="generator" content="OpenSencillo Framework (www.opensencillo.com)">';
199  }
200 
205  public function custom($code)
206  {
207  $this->header['custom'][] = $code;
208  }
209 
215  public function script($code)
216  {
217  $this->custom('<script type="text/javascript" src="'.$code.'"></script>');
218  }
219 
224  public function save()
225  {
226  $this->seo = $this->header['doctype-def'].PHP_EOL;
227  $this->seo .= (isset($this->header['html-def-snippet'])?$this->header['html-def-snippet']:$this->header['html-def']).PHP_EOL;
228  $this->seo .= $this->header['charset-def'].PHP_EOL;
229  $this->seo .= $this->header['responsive-def'].PHP_EOL;
230  $this->seo .= $this->header['title-def'].PHP_EOL;
231  $this->seo .= $this->header['description-def'].PHP_EOL;
232  $this->generator();
233 
234  unset($this->header['html-def']);
235  unset($this->header['html-def-snippet']);
236  unset($this->header['doctype-def']);
237  unset($this->header['charset-def']);
238  unset($this->header['responsive-def']);
239  unset($this->header['title-def']);
240  unset($this->header['description-def']);
241 
242  foreach($this->header as $key => $val)
243  {
244  if(!is_array($val))
245  {
246  $this->seo .= $val.PHP_EOL;
247  $this->info['head'][] = $key;
248  }
249  }
250  foreach($this->header['custom'] as $key => $val)
251  {
252  $this->seo .= $val.PHP_EOL;
253  $this->info['head'][] = $key;
254  }
255 
256  $this->seo .= $this->body;
257  return $this->seo;
258  }
259 
265  public function lang($lang)
266  {
267  unset($this->header['html-def']);
268  $this->header['html-def']='<html lang="'.$lang.'"><head>';
269  }
270 
274  public function googleLoad()
275  {
276  $this->header['jquery-js']='<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>';
277  $this->header['jqueryui-js']='<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>';
278  }
279 
283  public function jquery()
284  {
285  self::googleLoad();
286  }
287 
292  public function socialTags($arr, $snippet=false)
293  {
294  $this->custom('<meta property="og:url" content="'.$arr['url'].'" />');
295  $this->custom('<meta property="og:type" content="'.$arr['type'].'" />');
296  $this->custom('<meta property="og:title" content="'.$this->oginfo['title'].'" />');
297  $this->custom('<meta property="og:description" content="'.$this->oginfo['description'].'" />');
298  $this->custom('<meta property="og:image" content="'.$arr['image'].'" />');
299 
300  if($snippet)
301  {
302  $this->header['html-def-snippet'] = '<html itemscope itemtype="http://schema.org/Other"><head>';
303 
304  $this->custom('<meta itemprop="name" content="'.$this->oginfo['title'].'">');
305  $this->custom('<meta itemprop="description" content="'.$this->oginfo['description'].'">');
306  $this->custom('<meta itemprop="image" content="'.$arr['image'].'">');
307  }
308  }
309 
313  public function bootstrapDefs()
314  {
315  $this->header['bootstrap-css']='<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">';
316  $this->header['jquery-js']='<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>';
317  $this->header['bootstrap-js']='<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>';
318  }
319 }
320 
330 class coreSencillo implements coreInterface
331 {
332  public $info;
333  public $request;
334  public $original_request;
335  public $post;
336  public $get;
337 
338  private $authorized;
339  private $pid;
340 
344  public function __construct($sum=null)
345  {
346  $version = '2015';
347  $layout = '1';
348  $build = '07';
349  $this->info=array( 'CMS'=>'OpenSencillo',
350  'NME'=>'OpenSencillo',
351  'VSN'=>$version.'.'.$layout.$build,
352  'FWK'=>'OpenSencillo '.$version.'.'.$layout.$build,
353  'ARN'=>'Bc.Peter Horváth, Mastery s.r.o. CEO and FOUNDER',
354  'CPY'=>'&copy; COPYRIGHT 2011-'.date('Y').' Bc.Peter Horváth',
355  'HPE'=>'http://www.opensencillo.com',
356  'DTC'=>'01.'.$build.'.'.$version.':00.00:00.'.$layout.$build,
357  'PID'=>'PLEASE CONTACT info@opensencillo.com',
358  'SUM'=>$sum);
359  if($_GET['install']!='true')
360  {
361  $this->io_validator();
362  }
363  }
364 
365  public function version_info()
366  {
367  return $this->info;
368  }
369 
375  public function authorized($domains)
376  {
377  if(is_array($domains))
378  {
379  $this->authorized=$domains;
380  foreach($this->authorized as $value)
381  {
382  if($_SERVER['SERVER_NAME']==$value)
383  {
384  $this->pid[$value]=true;
385  }
386  else
387  {
388  $this->pid[$value]=false;
389  }
390  }
391  }
392  }
393 
397  public function product($path=false)
398  {
399  if($path==false)
400  {
401  $read = new fileSystem('http://auth.mastery.sk/action.php');
402  }
403  else
404  {
405  $read = new fileSystem('key.pid');
406  }
407  $exist= fopen($read->name,"rb");
408  if(!$exist)
409  {
410  die($this->info['PID']);
411  }
412  else
413  {
414  return $read->read();
415  }
416  }
417 
421  public function payLock()
422  {
423  if(!file_exists("key.pid"))
424  {
425  $json=json_decode(self::product(false),true);
426  $this->authorized($json['domains']);
427  if($this->pid[$_SERVER['SERVER_NAME']]!==true)
428  {
429  die($this->info['PID']);
430  }
431  $this->info['product']=$json;
432  if(($json['sum']!='none')&&(!empty($this->info['SUM']))&&($json['sum']==$this->info['SUM']))
433  {
434  $write = new fileSystem('key.pid');
435  $json['expired']=md5(date('Ym'));
436  $write->write(json_encode($json));
437  }
438  }
439  else
440  {
441  $json=json_decode(self::product(true),true);
442  $this->authorized($json['domains']);
443  if(($this->pid[$_SERVER['SERVER_NAME']]!==true)&&($json['sum']===$this->info['SUM']))
444  {
445  die($this->info['PID']);
446  }
447  $this->info['product']=$json;
448  if($this->info['product']['expired']!=md5(date('Ym')))
449  {
450  unlink('key.pid');
451  }
452  }
453  }
454 
460  private function io_rw($input)
461  {
462  $arr=array();
463 
464  foreach($input as $key=>$val)
465  {
466  if(is_string($val))
467  {
468  $arr[$key]=htmlspecialchars($val,ENT_COMPAT | ENT_HTML5);
469  $arr['admin_original'][$key]=$val;
470  }
471  }
472 
473  return $arr;
474  }
475 
481  private function io_validator()
482  {
483  $arr = array(
484  'request'=>$this->io_rw($_REQUEST),
485  'get'=>$this->io_rw($_GET),
486  'post'=>$this->io_rw($_POST)
487  );
488 
489  $arr['get']['core_info'] = $this->info;
490  $arr['request']['core_info']= $this->info;
491  $arr['post']['core_info'] = $this->info;
492  $arr['request']['status'] = 200;
493  $arr['get']['status'] = 200;
494  $arr['post']['status'] = 200;
495 
496  $_GET = $arr['get'];
497  $_POST = $arr['post'];
498  $_REQUEST = $arr['request'];
499 
500  $this->get = $arr['get'];
501  $this->post = $arr['post'];
502  $this->request = $arr['request'];
503 
504  if(($_GET['status']==200)&&($_POST['status']==200)&&($_REQUEST['status']==200))
505  {
506  return true;
507  }
508  else
509  {
510  return false;
511  }
512  }
513 
519  public function upgrade($source=null)
520  {
521  $fileList=scandir('./fw_core');
522 
523  foreach($fileList as $key=>$val)
524  {
525  if($key>1)
526  {
527  $md5 = md5_file('./fw_core/'.$val);
528  $remote_md5 = md5_file($source.$val.'.suf');
529  if($md5!=$remote_md5)
530  {
531  $read = new fileSystem($source.$val.'.suf');
532  $write= new fileSystem('./fw_core/'.$val);
533  $write->write($read->read());
534  }
535  }
536  }
537  }
538 
539  public function __destruct()
540  {
541  }
542 }
543 
555 class bootUp
556 {
557  public $coreSencillo;
558  public $headerSeo;
559  public $fileSystem;
560 
561  public function __construct($sum=false)
562  {
563  $this->headerSeo = new headerSeo;
564  $this->fileSystem = new fileSystem('firststart.json');
565 
566  if($sum)
567  {
568  $this->coreSencillo = new coreSencillo(json_decode($this->fileSystem->read(),true));
569  $this->fileSystem->payLock();
570  }
571  else
572  {
573  $this->coreSencillo = new coreSencillo;
574  }
575  }
576 }
577 $core = new bootUp(false);
578 ?>
encode($ec='UTF-8')
__construct($sum=null)
__construct($name)
owner($author)
description($data)
socialTags($arr, $snippet=false)
__destruct()
__construct($name)
product($path=false)