1: <?php
2: /**
3: * Description of AutoAppS
4: *
5: * @author Sartaj
6: */
7: include_once($phppath . "/controls/jquery.php");
8: include_once($libpath . "/lib/DIR.php");
9: include_once($phppath . "/classes/parser/minifier1/JavascriptMinifier.phpclass");
10:
11: class MobileAppJQuery extends \Sphp\tools\BasicApp{
12: private $dir = null;
13: private $jsonf = array();
14: private $key = 0;
15: public $outfolder = "apps/objs";
16:
17: public function onstart() {
18: $this->dir = new DIR();
19: }
20:
21: public function page_new() {
22: global $phppath;
23: $this->loadStarter();
24: $this->loadFrontPlaces();
25: $ty = new Sphp\tools\TempFile($phppath . "/apps/mobile/forms/index.temp");
26: $this->setTempFile($ty);
27: $pages = $this->loadPages();
28: file_put_contents($this->outfolder . "/pages.html", $pages);
29: $this->key += 1;
30: $this->jsonf[$this->key] = array("html",$this->outfolder . "/pages.html");
31: $ty->getComponent('dir1')->setInnerHTML($pages);
32: $this->getSphpJSCode();
33: $firstRunf["version"] = 1;
34: $firstRunf["files"] = $this->jsonf;
35: file_put_contents("apps/acfdb/firstrun.json", json_encode($firstRunf));
36: }
37: private function loadStarter() {
38: global $phppath,$respath;
39: addjQueryMobile();
40: addjQueryUI();
41: addBootStrap();
42: addFontAwesome();
43: addFileLink($this->apppath . "/objs/temp/css/framework.css");
44: addFileLink($respath . "/jslib/jquery/jslib.js");
45: addFileLink($respath . "/jslib/jqueryPlugin/jsstore.js");
46: addFileLink($respath . "/apps/mobile/core/jQmCore.js");
47: $this->key += 1;
48: $this->jsonf[$this->key] = array("js","https://proj.itkruze.com/res/apps/mobile/core/jQmCore.js");
49: $this->key += 1;
50: $this->jsonf[$this->key] = array("css",$this->apppath . "/objs/temp/css/framework.css");
51: addFileLink($this->outfolder . "/sphpapp" . '.js');
52: $this->loadJSLib("lib",true);
53: $this->loadJSLib("jsapps");
54: $this->loadJSLib("pages/js");
55: $this->loadJSLib("components/js");
56: $this->loadJSLib("frontplace/js");
57: }
58: private function loadFrontPlaces() {
59: addFrontPlace("emsg", $this->apppath . "/frontplace/ErrorMSG.front");
60: addFrontPlace("sidemenu",$this->apppath . "/frontplace/SideMenu.front");
61: //$this->key += 1;
62: //$this->jsonf[$this->key] = array("html", $this->outfolder . "/front.html");
63:
64: }
65: private function getSphpJSCode() {
66: global $respath;
67: $sphp_api = getSphpApi();
68: addHeaderJSFunction("ready", "ModuleObject.setHandler('onDeviceReady',function(){", "});",true);
69: $jscode = $sphp_api->getHeaderJS(false, true,2);
70: $jscode .= $sphp_api->getFooterJS(false, true,2);
71: $filepath = $this->apppath . "/gen/sphplib.js";
72: $this->key += 1;
73: $this->jsonf[$this->key] = array("js",$filepath);
74: file_put_contents($filepath, $jscode);
75: addFileLink($filepath);
76: }
77: private function loadJSLib($subpath,$overwrite=false) {
78: global $respath;
79: $lst = $this->dir->directorySearch($this->apppath . $subpath,".js");
80: $stro = "";
81: foreach ($lst as $key => $value) {
82: $stro .= file_get_contents($value[0] .'/' . $value[1]);
83: $stro .= '
84: ';
85: }
86: $minifier = new JavascriptMinifier ();
87: $filename = $this->outfolder . "/sphpapp" . '.js';
88: if($overwrite){
89: // $d = file_get_contents($respath . "/apps/mobile/core/jQmCore.js") .'
90: // ';
91: file_put_contents($filename, $minifier->Minify($stro));
92: }else{
93: file_put_contents($filename, $minifier->Minify($stro),FILE_APPEND);
94: }
95: $this->key += 1;
96: $this->jsonf[$this->key] = array("js",$filename);
97: }
98: private function loadPages() {
99: $header = new Sphp\tools\TempFile($this->apppath . "/components/header-bar.temp",false,$this);
100: $footer = new Sphp\tools\TempFile($this->apppath . "/components/footer-bar.temp",false,$this);
101: $header->run();
102: $footer->run();
103: $lst = $this->dir->directorySearch($this->apppath . "/pages/",".temp");
104: $stro = "";
105: foreach ($lst as $key => $value) {
106: //echo $value[1];
107: $t = new Sphp\tools\TempFile($value[0].$value[1],false,$this);
108: if($t->getMetaData('jQpage')->header){
109: $t->getMetaData('jQpage')->headerbar = $header->data;
110: addHeaderJSFunctionCode("ready", $t->getMetaData('jQpage')->pagename ."comp1" , 'PageObject.addCompName("' . $t->getMetaData('jQpage')->pagename . "page" . '","header-bar");',true);
111: }
112: if($t->getMetaData('jQpage')->footer){
113: $t->getMetaData('jQpage')->footerbar = $footer->data;
114: addHeaderJSFunctionCode("ready", $t->getMetaData('jQpage')->pagename ."comp2" , 'PageObject.addCompName("' . $t->getMetaData('jQpage')->pagename . "page" . '","footer-bar");',true);
115: }
116: $t->run();
117:
118: $stro .= $t->data;
119: }
120: return $stro;
121: }
122: }