Example #1
0
 function pageEntry($inPath)
 {
     $sm = new SJson();
     $testObject = new stdclass();
     $testObject->name = "SlightPHP";
     $testObject->value = array("min" => 1, "max" => 999);
     /**
      * 编码
      */
     print_r($tmp = $sm->encode($testObject));
     echo "\n";
     /**
      * 解码
      */
     print_r($sm->decode($tmp));
 }
Example #2
0
 public static function get_setting($name, $def = '')
 {
     if (!self::$_loaded_settings) {
         $settings_node = Node::get_node(self::Root, __CLASS__);
         if (!$settings_node) {
             self::$_loaded_settings = array();
         } else {
             self::$_loaded_settings = SJson::deserialize($settings_node->data);
         }
     }
     return array_key_exists($name, self::$_loaded_settings) ? self::$_loaded_settings[$name] : $def;
 }
Example #3
0
 public static function args2str($args)
 {
     self::obj2str($args);
     $tmp = SJson::encode($args);
     $tmp = str_replace("\\/", "/", $tmp);
     return substr($tmp, 1, strlen($tmp) - 2);
 }
Example #4
0
 public function get_avail_fields()
 {
     return $this->fields == '' ? array() : SJson::deserialize($this->fields);
 }
 function s_ajax_page_on_init()
 {
     if (!InPOST('__s_ajax_method')) {
         return;
     }
     $aj_method = _POST('__s_ajax_method');
     if (array_key_exists(AJ_INIT, $this->_events)) {
         foreach ($this->_events[AJ_INIT] as $method) {
             $res = call_user_func(array($this, $method), $aj_method);
             if ($this->_flow != PAGE_FLOW_NORMAL) {
                 if (isset($res)) {
                     echo "fail:{$res}";
                 }
                 $this->s_ajax_page_save_log();
                 return;
             }
         }
     }
     $this->_flow = PAGE_FLOW_BREAK;
     $method = "aj_{$aj_method}";
     if (!method_exists($this, $method)) {
         echo "fail:method {$method} not found";
         $this->s_ajax_page_save_log();
         return;
     }
     $args_array = SJson::deserialize(_POST('__s_ajax_args'));
     if (!is_array($args_array)) {
         echo "fail:fail to deserialize arguments";
         $this->s_ajax_page_save_log();
         return;
     }
     try {
         $res = call_user_func_array(array($this, $method), $args_array);
     } catch (Exception $ex) {
         echo 'fail:', $ex->getMessage();
         $this->s_ajax_page_save_log();
         return;
     }
     echo 'succ:';
     if (isset($res)) {
         echo SJson::serialize($res);
     }
     $this->s_ajax_page_save_log();
     exit;
 }
Example #6
0
 public function handle_ajax($obj)
 {
     if (!InPOST('__s_ajax_method')) {
         return false;
     }
     $method = 'aj_' . _POST('__s_ajax_method');
     if (!method_exists($obj, $method)) {
         echo "fail:method {$method} not found";
         return true;
     }
     $args_array = SJson::deserialize(_POST('__s_ajax_args'));
     if (!is_array($args_array)) {
         echo "fail:fail to deserialize arguments";
         return true;
     }
     try {
         $res = call_user_func_array(array($obj, $method), $args_array);
     } catch (Exception $ex) {
         echo 'fail:', $ex->getMessage();
         return true;
     }
     echo 'succ:';
     if (isset($res)) {
         echo SJson::serialize($res);
     }
     return true;
 }
 public function def_save_node(&$data, $node, $update_type = 0)
 {
     $prev_title = $node->title;
     $new_node_name = $node->name;
     if ($update_type != self::UPDATE_TYPE_NONE) {
         $node->title = trim(_POST('_title'));
         if ($node->title == '') {
             $data['errors']['_title'] = Loc::get('forms/validators/required');
         }
     }
     if ($update_type == self::UPDATE_TYPE_ALL) {
         $new_node_name = strtolower(trim(_POST('_name')));
         if ($new_node_name == '') {
             $new_node_name = Cms::title_to_name($node->title);
         }
         if ($node->title != '' && $new_node_name == '') {
             $data['errors']['_name'] = Loc::get('forms/validators/required');
         }
         if ($new_node_name != '') {
             if (!Cms::node_name_is_valid($new_node_name)) {
                 $data['errors']['_name'] = Loc::get('cms/admin/node/invalid_name');
             } elseif (!$node->parent_node) {
                 $data['errors']['_name'] = Loc::get('cms/admin/node/not_found_dunno', array($path_prepend));
             } else {
                 foreach ($node->parent_node->childs as $nd) {
                     if ($nd->name == $new_node_name && $nd->id != $node->id) {
                         $data['errors']['_name'] = Loc::get('cms/admin/node/exists');
                         break;
                     }
                 }
             }
         }
     }
     foreach ($node->accessors as $name => $opts) {
         if (isset($node->editable_fields[$name]['type']) && $node->editable_fields[$name]['type'] == 'keyvalue') {
             $do_trim = isset($node->editable_fields[$name]['trim']) && $node->editable_fields[$name]['trim'];
             $list = $node->{$name} == '' ? array() : SJson::deserialize($node->{$name});
             $new_list = array();
             for ($i = 0; $i < count($list); $i++) {
                 if (!inPOST("{$name}_rm_{$i}")) {
                     $key = trim(_POST("{$name}_k_{$i}"));
                     if ($key != '') {
                         $value = _POST("{$name}_v_{$i}");
                         if ($do_trim) {
                             $value = trim($value);
                         }
                         $new_list[$key] = $value;
                     }
                 }
             }
             $key = trim(_POST("{$name}_nk"));
             if ($key != '') {
                 $value = _POST("{$name}_nv");
                 if ($do_trim) {
                     $value = trim($value);
                 }
                 $new_list[$key] = $value;
             }
             $node->{$name} = SJson::serialize($new_list);
         } elseif (inPOST($name)) {
             $node->{$name} = _POST($name);
         }
     }
     if (!isset($data['errors']) || !count($data['errors'])) {
         Node::lock();
         $was_new_node = $node->is_new();
         if (!$node->position) {
             $node->position = Node::get_max_position($node->path) + 1;
         }
         if ($update_type == self::UPDATE_TYPE_ALL && $new_node_name != $node->name) {
             $node->rename($new_node_name);
             $name_updated = true;
         } else {
             $node->save();
             $name_updated = false;
         }
         Node::unlock();
         $data['info'] = Loc::get('cms/admin/saved');
         if ($node->title != $prev_title || $name_updated) {
             if ($was_new_node) {
                 $_SESSION['s.cms.admin.just-saved'] = true;
                 header('Location: ' . ROOT . "admin/module.php?node_id={$node->id}");
                 exit;
             }
             $data['extra']['update_tree'] = true;
         }
         $data['extra']['select_node'] = $node->id;
     }
 }