Hi,
I recently had to create a email service using a cron job and scriptcase. When you use a blank app there are still some libraries that get called where the paths will not work properly.
Disable security and enable direct call on the page. Otherwise if you try to call it on the command line you will see a bunch of html containing an error.
All the changes below will need to happen on the server you deploy your project to.
Just a note wherever you see “/path/to/deployed/scriptcase/site/” below that is the path to where the _lib file is located. So if your is located in “/www/my_site/” and inside the “my_site” folder is the “_lib” file then you put “/www/my_site/” wherever “/path/to/deployed/scriptcase/site/” apears.
Go into your my_blank_app_name folder then into my_blank_app_name.php and change the path to only be “index.php”.
Then go in to the “index.php” file and look for the following:
/*
$str_path_apl_url = $_SERVER[‘PHP_SELF’];
$str_path_apl_url = str_replace("\", ‘/’, $str_path_apl_url);
$str_path_apl_url = substr($str_path_apl_url, 0, strrpos($str_path_apl_url, “/”));
$str_path_apl_url = substr($str_path_apl_url, 0, strrpos($str_path_apl_url, “/”)+1);
$str_path_apl_dir = substr($str_path_sys, 0, strrpos($str_path_sys, “/”));
$str_path_apl_dir = substr($str_path_apl_dir, 0, strrpos($str_path_apl_dir, “/”)+1);
*/
This is where scriptcase tries to dynamicly find the path but this only works when calling the page from the browser. If you want to call it from a cron job or directly on the command line comment that code out and just add:
$str_path_apl_url = "/path/to/deployed/scriptcase/site/";
Then go down and update the paths for the following varaibles:
/*
$str_path_web = $_SERVER['PHP_SELF'];
$str_path_web = str_replace("\\", '/', $str_path_web);
$str_path_web = str_replace('//', '/', $str_path_web);
*/
Replace with $str_path_web = "/path/to/deployed/scriptcase/site/";
/*
$this->root = substr($str_path_sys, 0, -1 * strlen($str_path_web));
*/
Replace with $this->root = "/path/to/deployed/scriptcase/site/";
/*
$this->path_link = substr($str_path_web, 0, strrpos($str_path_web, '/'));
$this->path_link = substr($this->path_link, 0, strrpos($this->path_link, '/')) . '/';
*/
Replace with $this->path_link = "";
After updating all those variables you will have to update the paths with them as needed.
To give you a idea this is what my paths looks like:
$this->path_botoes = $this->root . $this->path_link . "_lib/img";
$this->path_img_global = $this->root . $this->path_link . "_lib/img";
$this->path_img_modelo = $this->root . $this->path_link . "_lib/img";
$this->path_icones = $this->root . $this->path_link . "_lib/img";
$this->path_imag_cab = $this->root . $this->path_link . "_lib/img";
$this->path_help = $this->root . $this->path_link . "_lib/webhelp/";
$this->path_font = $this->root . $this->path_link . "_lib/font/";
$this->path_btn = $this->root . $this->path_link . "_lib/buttons/";
$this->path_css = $this->root . $this->path_link . "_lib/css/";
$this->path_lib_php = $this->root . $this->path_link . "_lib/lib/php";
$this->path_lib_js = $this->root . $this->path_link . "_lib/lib/js";
$this->path_lang = $this->root . "/_lib/lang/";
$this->path_lang_js = $this->root . "/_lib/js/";
$this->path_chart_theme = $this->root . $this->path_link . "_lib/chart/";
$this->path_cep = $this->root . $this->path_prod . "/cep";
$this->path_cor = $this->root . $this->path_prod . "/cor";
$this->path_js = $this->root . $this->path_prod . "/lib/js";
$this->path_libs = $this->root . $this->path_prod . "/lib/php";
$this->path_third = $this->root . $this->path_prod . "/third";
$this->path_secure = $this->root . $this->path_prod . "/secure";
$this->path_adodb = $this->root . $this->path_prod . "/third/adodb";
The downside of this is that now anyone can call this page using its name in the URL. To avoid this you will have to update more variables. In our case the code of the php file will very rarely need to be updated but if you will have to update the code in the php file often this approach might not be usefull.
If you want to move the whole blank app to a diffrent folder on the server where users on the frontend wont be able to call it change the following.
Look for the:
if (!function_exists("sc_check_mobile"))
Inside it you will see an path that fails. Replace the start of the path with “/path/to/deployed/scriptcase/site/”.
Keep the rest of the path connected to it just replace the front of the path. (The rest of the path should be something like “_lib/lib/php/nm_check_mobile.php”.
Then look for the following if’s:
if (!function_exists("SC_dir_app_ini"))
if (!function_exists("NM_is_utf8"))
and do what you did for the if above where you just replace the front of the path.
Then look for the following code:
<META http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT"/> <META http-equiv="Pragma" content="no-cache"/>
Below it there will be some broken paths. Update them to work. I can’t remember what they looked like before I updated them but this is what they look like now:
<link rel="shortcut icon" href="<?php echo $this->root . _lib/img/scriptcase__NM__ico__NM__favicon.ico?>">
<script type="text/javascript" src="<?php echo $this->Ini->path_prod ?>/third/jquery/js/jquery.js"></script>
<script type="text/javascript">var sc_pathToTB = '<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/';</script>
<script type="text/javascript" src="<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/thickbox-compressed.js"></script>
<link rel="stylesheet" href="<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/thickbox.css" type="text/css" media="screen" />
That should be everything.
If you see any other html errors inside the html there should be some kind of error. That’s the way scriptcase handles the errors by printing it to a html body. Had this happen a lot when I started working on creating API’s in scriptcase.