Example #1
0
 function styles()
 {
     $applets = Applet::get_applets();
     $all_styles = array();
     foreach ($applets as $applet) {
         $style = file_exists($applet->style_file) ? file_get_contents($applet->style_file) : '';
         if (!empty($style)) {
             $all_styles[] = $style;
         }
     }
     header('Content-type: text/css');
     header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
     echo join("\n", $all_styles);
     exit(0);
 }
Example #2
0
 private function get_flow($flow_id = 0)
 {
     if ($flow_id < 1) {
         $flow_id = $this->flow_id;
     }
     if (is_null($this->flow)) {
         $this->flow = VBX_Flow::get(array('id' => $flow_id, 'numbers' => false));
     }
     if ($flow_id > 0) {
         if (!empty($this->flow)) {
             if ($this->flow_type == 'sms') {
                 // make flow data visible to all applets
                 Applet::$flow_data = $this->flow->sms_data;
             } else {
                 // make flow data visible to all applets
                 Applet::$flow_data = $this->flow->data;
             }
         }
     }
     return $this->flow;
 }
<?php

// Config
define("APPLET_ID", "CCNDGQYS");
$rootUrl = $_SERVER['DOCUMENT_ROOT'];
include_once $rootUrl . "/php_model/applet.model.php";
// Init object
$a_m = new Applet();
// If submit action?
if (isset($_POST) && count($_POST) > 0) {
    if (isset($_POST['input-name']) && !empty($_POST['input-name'])) {
        // Get params
        $inputName = htmlspecialchars(mysql_real_escape_string($_POST['input-name']));
        if (isset($_GET['id']) && !empty($_GET['id'])) {
            $id = mysql_real_escape_string($_GET['id']);
        } else {
            exit;
        }
        // Generate result
        $rand = rand(5, 300) * 1000 . "." . rand(1, 99);
        setlocale(LC_MONETARY, "zh_CN");
        $money_earn = money_format("%i", $rand);
        $money_earn_format = substr($money_earn, 3);
        $resultTxt = "经过测量与计算发现 <b>" . $inputName . "</b> 在今年剩余的时间里能够赚得:</br></br><b>¥" . $money_earn_format . "</b>";
        // Display tpl
        $arr = array();
        $intval = intval($rand);
        if ($intval < 50000) {
            $arr['tpl_title'] = $inputName . " 的财运被算出来了,他需要被安慰...";
        } else {
            if ($intval < 150000 && $intval > 50000) {
Example #4
0
 public static function get_applets($flow_type = 'voice')
 {
     $applets = array();
     $applet_names_by_plugin = array();
     $plugin_dir_names = scandir(PLUGIN_PATH);
     foreach ($plugin_dir_names as $plugin_dir_name) {
         // Ignore current pwd
         if ($plugin_dir_name[0] == '.') {
             continue;
         }
         // Add to applet collection if contains an applets dir
         $applets_path = PLUGIN_PATH . '/' . $plugin_dir_name . '/applets';
         if (is_dir($applets_path)) {
             $applet_names_by_plugin[$plugin_dir_name] = scandir($applets_path);
         }
     }
     // Iterate each applet to check for valid structure and create an instance
     foreach ($applet_names_by_plugin as $plugin_dir_name => $applet_dir_names) {
         foreach ($applet_dir_names as $applet_dir_name) {
             // Ignore current pwd
             if ($applet_dir_name[0] == '.') {
                 continue;
             }
             try {
                 $applet = null;
                 $applet_path = PLUGIN_PATH . '/' . $plugin_dir_name . '/applets/' . $applet_dir_name;
                 // Sanity check and make sure this path is accessible
                 if (!is_dir($applet_path)) {
                     throw new AppletException("Applet path inaccessible {$applet_path}");
                 }
                 // Check for required files
                 $required_min = count(self::$requiredFiles);
                 $files = scandir($applet_path);
                 // If we have the minimum number of required files, lets move on.
                 $required = array_intersect(self::$requiredFiles, $files);
                 if (count($required) < $required_min) {
                     throw new AppletException("Missing a required file, found: " . implode(', ', $files) . "\nRequired: " . implode(', ', self::$requiredFiles));
                 }
                 /* Process configuration */
                 $applet_config = file_get_contents($applet_path . '/applet.json');
                 $applet_config = json_decode($applet_config);
                 if (is_null($applet_config)) {
                     throw new AppletException("Syntax error in applet.json");
                 }
                 /* Build Applet Instance */
                 $applet = Applet::get($plugin_dir_name, $applet_dir_name, $applet_config);
                 $applet->flow_type = $flow_type;
                 if (is_null($applet)) {
                     throw new AppletException("Failed to create instance of applet");
                 }
                 $applets[$applet->id] = $applet;
             } catch (AppletException $e) {
                 // Your applet developer has failed you at this point
                 $message = "An error occurred loading applet: {$applet_dir_name} from {$plugin_dir_name}";
                 // Notify the user
                 $ci =& get_instance();
                 $ci->session->set_userdata('error', $message);
                 // Next applet in the list
                 continue;
             }
         }
     }
     uasort($applets, array("Applet", "applet_sort"));
     return $applets;
 }
Example #5
0
 private function get_flow($flow_id = 0)
 {
     if ($flow_id < 1) {
         $flow_id = $this->flow_id;
     }
     if (is_null($this->flow)) {
         $this->flow = VBX_Flow::get($flow_id);
     }
     if ($flow_id > 0) {
         if (!empty($flow)) {
             if ($this->flow_type == 'sms') {
                 Applet::$flow_data = $flow->sms_data;
                 // make flow data visible to all applets
             } else {
                 Applet::$flow_data = $flow->data;
                 // make flow data visible to all applets
             }
         }
     }
     return $this->flow;
 }