Ejemplo n.º 1
0
 /**
  * 获取项目JS代码
  * 
  * @param unknown $id        	
  * @param string $type
  *        	nomal为js.php, hook为hook.js, 这会让{pmx.system.projurl}的值不一样
  * @return boolean|string
  */
 public function getCode($id, $type = "normal", $urlext = "")
 {
     global $table_prefix;
     if (!$this->isExistID($id)) {
         return FALSE;
     }
     $detail = $this->getDetail($id);
     $saltid = $detail['saltid'];
     /**
      * 获取模块ID
      */
     $mods = json_decode($detail["mods"]);
     /**
      * 获取项目的模块参数配置
      */
     $projModConfig = json_decode($detail["modConfig"]);
     if (count($mods) <= 0) {
         return FALSE;
     }
     $pmxMod = new pmxModule();
     $jscode = "";
     /**
      * 把模块参数配置整合到原始模块代码里
      */
     foreach ($mods as $modid) {
         // BUGS
         if ($pmxMod->isExistID($modid)) {
             $code = $pmxMod->getDetail($modid)['code'];
             $config = $pmxMod->getConfig($modid);
             // echo "\n=============\n$modid";
             // var_dump($config);
             $search = array();
             if (count($config) > 0) {
                 foreach ($config as $config_item) {
                     $search_item["search"] = "{pmx.define." . $config_item[0] . "}";
                     if (count($projModConfig) > 0) {
                         foreach ($projModConfig as $modConfig_item) {
                             if ($modConfig_item[0] == $modid) {
                                 if ($modConfig_item[1] == $config_item[0]) {
                                     $search_item["replace"] = $modConfig_item[2];
                                     break;
                                 } else {
                                     $search_item["replace"] = "";
                                 }
                             }
                         }
                     } else {
                         $search_item["replace"] = "";
                     }
                     $search[] = $search_item;
                     // var_dump($search_item);
                 }
             }
             $search[] = array("search" => "{pmx.system.projid}", "replace" => $saltid);
             if ($type != "hook") {
                 $search[] = array("search" => "{pmx.system.projurl}", "replace" => (new pmxURL())->get_request_puburl($saltid));
             } else {
                 $search[] = array("search" => "{pmx.system.projurl}", "replace" => (new pmxURL())->get_response_puburl($saltid, $urlext));
             }
             /**
              * 为主机记录生成SID
              */
             $sid = $this->newSaltID(50);
             while ((new pmxHost())->isExistSaltID($sid)) {
                 $sid = $this->newSaltID(50);
             }
             $search[] = array("search" => "{pmx.system.hookurl}", "replace" => (new pmxURL())->get_hook_puburl($saltid, $sid . "/"));
             // echo $modid." : ";
             // var_dump($search);
             if (count($search) > 0) {
                 foreach ($search as $search_item) {
                     if (trim($search_item["search"]) != "" && trim($code) != "") {
                         $code = str_replace($search_item["search"], $search_item["replace"], $code);
                         // echo "\n===============\n{$modid}*str_replace(".$search_item["search"].", ".$search_item["replace"].', $code);'."\t\n".$code;
                     }
                 }
             }
             $jscode = $jscode . $code . "\n";
         }
     }
     return $jscode;
 }
Ejemplo n.º 2
0
<?php

/**
 * 获取模块配置
 */
if (!defined("PMX_ENTRANCE")) {
    header("HTTP/1.0 404 Not Found");
    exit;
}
header('Content-Type: text/json; charset=utf-8');
$id = isset($_GET["id"]) ? intval($_GET["id"]) : NULL;
$pmxModule = new pmxModule();
$json_data = array("status" => "0", "msg" => "", "data" => "");
if (!pmx_validate_token()) {
    $json_data = array("status" => "0", "msg" => "Token is incorrect.", "data" => "");
    die(json_encode($json_data));
}
if (!$pmxModule->isExistID($id)) {
    $json_data = array("status" => "0", "msg" => "The module id is non-existent.", "data" => "");
    die(json_encode($json_data));
}
$data = $pmxModule->getConfig($id);
$json_data = array("status" => "1", "msg" => "success.", "data" => $data);
echo json_encode($json_data);