Menu.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. include_once(__DIR__."/../../utils/Utils.class.php");
  3. include_once(__DIR__."/../../utils/error.inc.php");
  4. class Menu {
  5. public $button = null; // xxxMenu array, 即各种子菜单array
  6. public function __construct($xxmenuArray=null)
  7. {
  8. $this->button = $xxmenuArray;
  9. }
  10. public static function CheckMenuCreateArgs($menu) {
  11. }
  12. public static function Array2Menu($arr)
  13. {
  14. $menu = new Menu();
  15. foreach($arr["button"] as $item) {
  16. $subButton = null;
  17. if ( ! array_key_exists("type", $item)) {
  18. $subButton = SubMenu::Array2Menu($item);
  19. } else {
  20. $type = $item["type"];
  21. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  22. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  23. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  24. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  25. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  26. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  27. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  28. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  29. }
  30. $menu->button[] = $subButton;
  31. }
  32. return $menu;
  33. }
  34. } // class
  35. // ------------------------ 各种类型子菜单 ------------------------------------
  36. class SubMenu {
  37. public $name = null; // string
  38. public $sub_button = null; // xxxMenu array
  39. public function __construct($name=null, $xxmenuArray=null)
  40. {
  41. $this->name = $name;
  42. $this->sub_button = $xxmenuArray;
  43. }
  44. public static function Array2Menu($arr)
  45. {
  46. $menu = new SubMenu();
  47. $menu->name = Utils::arrayGet($arr, "name");
  48. foreach($arr["sub_button"] as $item) {
  49. $subButton = null;
  50. if ( ! array_key_exists("type", $item)) {
  51. $subButton = SubMenu::Array2Menu($item);
  52. } else {
  53. $type = $item["type"];
  54. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  55. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  56. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  57. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  58. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  59. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  60. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  61. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  62. }
  63. $menu->sub_button[] = $subButton;
  64. }
  65. return $menu;
  66. }
  67. }
  68. class ClickMenu {
  69. public $type = "click";
  70. public $name = null; // string
  71. public $key = null; // string
  72. public function __construct($name=null, $key=null, $xxmenuArray=null)
  73. {
  74. $this->name = $name;
  75. $this->key = $key;
  76. }
  77. public static function Array2Menu($arr)
  78. {
  79. $menu = new ClickMenu();
  80. $menu->type = Utils::arrayGet($arr, "type");
  81. $menu->name = Utils::arrayGet($arr, "name");
  82. $menu->key = Utils::arrayGet($arr, "key");
  83. return $menu;
  84. }
  85. }
  86. class viewMenu {
  87. public $type = "view";
  88. public $name = null; // string
  89. public $url = null; // string
  90. public function __construct($name=null, $url= null)
  91. {
  92. $this->name = $name;
  93. $this->url = $url;
  94. }
  95. public static function Array2Menu($arr)
  96. {
  97. $menu = new viewMenu();
  98. $menu->type = "view";
  99. $menu->name = Utils::arrayGet($arr, "name");
  100. $menu->url = Utils::arrayGet($arr, "url");
  101. return $menu;
  102. }
  103. }
  104. class ScanCodePushMenu {
  105. public $type = "scancode_push";
  106. public $name = null; // string
  107. public $key = null; // string
  108. public $sub_button = null; // xxxMenu array
  109. public function __construct($name=null, $key=null, $xxmenuArray=null)
  110. {
  111. $this->name = $name;
  112. $this->key = $key;
  113. $this->sub_button = $xxmenuArray;
  114. }
  115. public static function Array2Menu($arr)
  116. {
  117. $menu = new ScanCodePushMenu();
  118. $menu->type = Utils::arrayGet($arr, "type");
  119. $menu->name = Utils::arrayGet($arr, "name");
  120. $menu->key = Utils::arrayGet($arr, "key");
  121. foreach($arr["sub_button"] as $item) {
  122. $subButton = null;
  123. if ( ! array_key_exists("type", $item)) {
  124. $subButton = SubMenu::Array2Menu($item);
  125. } else {
  126. $type = $item["type"];
  127. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  128. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  129. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  130. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  131. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  132. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  133. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  134. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  135. }
  136. $menu->sub_button[] = $subButton;
  137. }
  138. return $menu;
  139. }
  140. }
  141. class ScanCodeWaitMsgMenu {
  142. public $type = "scancode_waitmsg";
  143. public $name = null; // string
  144. public $key = null; // string
  145. public $sub_button = null; // xxxMenu array
  146. public function __construct($name=null, $key=null, $xxmenuArray=null)
  147. {
  148. $this->name = $name;
  149. $this->key = $key;
  150. $this->sub_button = $xxmenuArray;
  151. }
  152. public static function Array2Menu($arr)
  153. {
  154. $menu = new ScanCodeWaitMsgMenu();
  155. $menu->type = Utils::arrayGet($arr, "type");
  156. $menu->name = Utils::arrayGet($arr, "name");
  157. $menu->key = Utils::arrayGet($arr, "key");
  158. foreach($arr["sub_button"] as $item) {
  159. $subButton = null;
  160. if ( ! array_key_exists("type", $item)) {
  161. $subButton = SubMenu::Array2Menu($item);
  162. } else {
  163. $type = $item["type"];
  164. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  165. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  166. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  167. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  168. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  169. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  170. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  171. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  172. }
  173. $menu->sub_button[] = $subButton;
  174. }
  175. return $menu;
  176. }
  177. }
  178. class PicSysPhotoMenu {
  179. public $type = "pic_sysphoto";
  180. public $name = null; // string
  181. public $key = null; // string
  182. public $sub_button = null; // xxxMenu array
  183. public function __construct($name=null, $key=null, $xxmenuArray=null)
  184. {
  185. $this->name = $name;
  186. $this->key = $key;
  187. $this->sub_button = $xxmenuArray;
  188. }
  189. public static function Array2Menu($arr)
  190. {
  191. $menu = new PicSysPhotoMenu();
  192. $menu->type = Utils::arrayGet($arr, "type");
  193. $menu->name = Utils::arrayGet($arr, "name");
  194. $menu->key = Utils::arrayGet($arr, "key");
  195. foreach($arr["sub_button"] as $item) {
  196. $subButton = null;
  197. if ( ! array_key_exists("type", $item)) {
  198. $subButton = SubMenu::Array2Menu($item);
  199. } else {
  200. $type = $item["type"];
  201. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  202. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  203. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  204. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  205. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  206. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  207. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  208. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  209. }
  210. $menu->sub_button[] = $subButton;
  211. }
  212. return $menu;
  213. }
  214. }
  215. class PicPhotoOrAlbumMenu {
  216. public $type = "pic_photo_or_album";
  217. public $name = null; // string
  218. public $key = null; // string
  219. public $sub_button = null; // xxxMenu array
  220. public function __construct($name=null, $key=null, $xxmenuArray=null)
  221. {
  222. $this->name = $name;
  223. $this->key = $key;
  224. $this->sub_button = $xxmenuArray;
  225. }
  226. public static function Array2Menu($arr)
  227. {
  228. $menu = new PicPhotoOrAlbumMenu();
  229. $menu->type = Utils::arrayGet($arr, "type");
  230. $menu->name = Utils::arrayGet($arr, "name");
  231. $menu->key = Utils::arrayGet($arr, "key");
  232. foreach($arr["sub_button"] as $item) {
  233. $subButton = null;
  234. if ( ! array_key_exists("type", $item)) {
  235. $subButton = SubMenu::Array2Menu($item);
  236. } else {
  237. $type = $item["type"];
  238. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  239. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  240. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  241. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  242. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  243. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  244. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  245. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  246. }
  247. $menu->sub_button[] = $subButton;
  248. }
  249. return $menu;
  250. }
  251. }
  252. class PicWeixinMenu {
  253. public $type = "pic_weixin";
  254. public $name = null; // string
  255. public $key = null; // string
  256. public $sub_button = null; // xxxMenu array
  257. public function __construct($name=null, $key=null, $xxmenuArray=null)
  258. {
  259. $this->name = $name;
  260. $this->key = $key;
  261. $this->sub_button = $xxmenuArray;
  262. }
  263. public static function Array2Menu($arr)
  264. {
  265. $menu = new PicWeixinMenu();
  266. $menu->type = Utils::arrayGet($arr, "type");
  267. $menu->name = Utils::arrayGet($arr, "name");
  268. $menu->key = Utils::arrayGet($arr, "key");
  269. foreach($arr["sub_button"] as $item) {
  270. $subButton = null;
  271. if ( ! array_key_exists("type", $item)) {
  272. $subButton = SubMenu::Array2Menu($item);
  273. } else {
  274. $type = $item["type"];
  275. if ($type == "click") $subButton = ClickMenu::Array2Menu($item);
  276. if ($type == "view") $subButton = viewMenu::Array2Menu($item);
  277. if ($type == "scancode_push") $subButton = ScanCodePushMenu::Array2Menu($item);
  278. if ($type == "scancode_waitmsg") $subButton = ScanCodeWaitMsgMenu::Array2Menu($item);
  279. if ($type == "pic_sysphoto") $subButton = PicSysPhotoMenu::Array2Menu($item);
  280. if ($type == "pic_photo_or_album") $subButton = PicPhotoOrAlbumMenu::Array2Menu($item);
  281. if ($type == "pic_weixin") $subButton = PicWeixinMenu::Array2Menu($item);
  282. if ($type == "location_select") $subButton = LocationSelectMenu::Array2Menu($item);
  283. }
  284. $menu->sub_button[] = $subButton;
  285. }
  286. return $menu;
  287. }
  288. }
  289. class LocationSelectMenu {
  290. public $type = "location_select";
  291. public $name = null; // string
  292. public $key = null; // string
  293. public function __construct($name=null, $key=null, $xxmenuArray=null)
  294. {
  295. $this->name = $name;
  296. $this->key = $key;
  297. }
  298. public static function Array2Menu($arr)
  299. {
  300. $menu = new LocationSelectMenu();
  301. $menu->type = Utils::arrayGet($arr, "type");
  302. $menu->name = Utils::arrayGet($arr, "name");
  303. $menu->key = Utils::arrayGet($arr, "key");
  304. return $menu;
  305. }
  306. }