Manage.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 获取标签信息:根据名称获取多个标签,一般用于autocomplete
  8. *
  9. * @return mixed
  10. */
  11. public function getByCreaterName_api()
  12. {
  13. $data = Dever::db('content/creater')->getAllByName(array
  14. (
  15. 'name' => Dever::input('term'))
  16. );
  17. if ($data) {
  18. return $data;
  19. }
  20. return array
  21. (
  22. 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
  23. );
  24. }
  25. private function search($table = 'content/news', $type = false)
  26. {
  27. $keyword = Dever::input('keyword');
  28. $yes = Dever::input('yes');
  29. $where = array();
  30. if ($type) {
  31. $where['type'] = $type;
  32. }
  33. if ($yes) {
  34. $yes = Dever::db($table)->search(array('ids' => $yes));
  35. }
  36. if (!$keyword) {
  37. $where['limit'] = '0,50';
  38. $data = Dever::db($table)->search($where);
  39. } else {
  40. $where['name'] = $keyword;
  41. $data = Dever::db($table)->search($where);
  42. }
  43. $result = array();
  44. if ($yes) {
  45. foreach ($yes as $k => $v) {
  46. if (isset($data[$k])) {
  47. unset($data[$k]);
  48. }
  49. $yes[$k]['selected'] = 'selected';
  50. }
  51. $data = $yes + $data;
  52. $data = array_merge($data, array());
  53. } else {
  54. $data = array_merge($data, array());
  55. }
  56. if (!$data) {
  57. Dever::alert('暂无数据');
  58. }
  59. return $data;
  60. }
  61. # 搜索文章
  62. public function search_news_api()
  63. {
  64. return $this->search('content/news', 1);
  65. }
  66. # 搜索专题
  67. public function search_feature_api()
  68. {
  69. return $this->search('content/news', 2);
  70. }
  71. # 搜索视频
  72. public function search_video_api()
  73. {
  74. return $this->search('content/news', 3);
  75. }
  76. # 搜索活动
  77. public function search_act_api()
  78. {
  79. return $this->search('content/news', 4);
  80. }
  81. # 搜索造物主
  82. public function search_creater_api()
  83. {
  84. return $this->search('content/creater');
  85. }
  86. # 搜索虚拟人
  87. public function search_xuniren_api()
  88. {
  89. return $this->search('content/xuniren');
  90. }
  91. public function updateCreater($id, $name, $data)
  92. {
  93. $name = Dever::param('name', $data);
  94. if ($name) {
  95. $first = mb_substr($name, 0, 1);
  96. if (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $first)) {
  97. $pinyin = new zh2py();
  98. $first = $pinyin::conv($first);
  99. }
  100. $shou = strtolower($first);
  101. $update['shou'] = $shou;
  102. $update['where_id'] = $id;
  103. Dever::db('content/creater')->update($update);
  104. }
  105. }
  106. public function updateXnr($id, $name, $data)
  107. {
  108. $ename = Dever::param('name', $data);
  109. if ($ename) {
  110. $first = mb_substr($ename, 0, 1);
  111. if (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $first)) {
  112. $pinyin = new zh2py();
  113. $first = $pinyin::conv($first);
  114. }
  115. $shou = strtolower($first);
  116. $update['shou'] = $shou;
  117. $update['where_id'] = $id;
  118. Dever::db('content/xuniren')->update($update);
  119. }
  120. }
  121. }
  122. class zh2py
  123. {
  124. //根据汉字区位表,(http://www.mytju.com/classcode/tools/QuWeiMa_FullList.asp)
  125. //我们可以看到从16-55区之间是按拼音字母排序的,所以我们只需要判断某个汉字的区位码就可以得知它的拼音首字母.
  126. //区位表第一部份,按拼音字母排序的.
  127. //16区-55区
  128. /*
  129. 'A'=>0xB0A1, 'B'=>0xB0C5, 'C'=>0xB2C1, 'D'=>0xB4EE, 'E'=>0xB6EA, 'F'=>0xB7A2, 'G'=>0xB8C1,'H'=>0xB9FE,
  130. 'J'=>0xBBF7, 'K'=>0xBFA6, 'L'=>0xC0AC, 'M'=>0xC2E8, 'N'=>0xC4C3, 'O'=>0xC5B6, 'P'=>0xC5BE,'Q'=>0xC6DA,
  131. 'R'=>0xC8BB, 'S'=>0xC8F6, 'T'=>0xCBFA, 'W'=>0xCDDA, 'X'=>0xCEF4, 'Y'=>0xD1B9, 'Z'=>0xD4D1
  132. */
  133. private static $FirstTable = array(
  134. 0xB0C5, 0xB2C1, 0xB4EE, 0xB6EA, 0xB7A2, 0xB8C1, 0xB9FE, 0xBBF7, 0xBFA6, 0xC0AC, 0xC2E8,
  135. 0xC4C3, 0xC5B6, 0xC5BE, 0xC6DA, 0xC8BB, 0xC8F6, 0xCBFA, 0xCDDA, 0xCEF4, 0xD1B9, 0xD4D1,0xD7FA
  136. );
  137. private static $FirstLetter = "ABCDEFGHJKLMNOPQRSTWXYZ";
  138. //区位表第二部份,不规则的,下面的字母是每个区里面对应字的拼音首字母.从网上查询整理出来的,可能会有部份错误.
  139. //56区-87区
  140. private static $SecondTable = array(
  141. "CJWGNSPGCGNEGYPBTYYZDXYKYGTZJNMJQMBSGZSCYJSYYFPGKBZGYDYWJKGKLJSWKPJQHYJWRDZLSYMRYPYWWCCKZNKYYG",
  142. "TTNGJEYKKZYTCJNMCYLQLYPYSFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCKBPHFFSSTYBGMXLPBYLLBHLX",
  143. "SMZMYJHSOJNGHDZQYKLGJHSGQZHXQGKXZZWYSCSCJXYEYXADZPMDSSMZJZQJYZCJJFWQJBDZBXGZNZCPWHWXHQKMWFBPBY",
  144. "DTJZZKXHYLYGXFPTYJYYZPSZLFCHMQSHGMXXSXJYQDCSBBQBEFSJYHWWGZKPYLQBGLDLCDTNMAYDDKSSNGYCSGXLYZAYPN",
  145. "PTSDKDYLHGYMYLCXPYCJNDQJWXQXFYYFJLEJPZRXCCQWQQSBZKYMGPLBMJRQCFLNYMYQMSQYRBCJTHZTQFRXQHXMQJCJLY",
  146. "QGJMSHZKBSWYEMYLTXFSYDXWLYCJQXSJNQBSCTYHBFTD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NMSHRPHQQJCHGMFPRXHJGDYCHGHLYRZQLCYQJNZSQTKQJYMSZSWLCFQQQXYFGGYPTQWLMCRNFKKFSYYLQBMQAMM",
  168. "MYXCTPSHCPTXXZZSMPHPSHMCLMLDQFYQXSZYJDJJZZHQPDSZGLSTJBCKBXYQZJSGPSXQZQZRQTBDKYXZKHHGFLBCSMDLDG",
  169. "DZDBLZYYCXNNCSYBZBFGLZZXSWMSCCMQNJQSBDQSJTXXMBLTXZCLZSHZCXRQJGJYLXZFJPHYMZQQYDFQJJLZZNZJCDGZYG",
  170. "CTXMZYSCTLKPHTXHTLBJXJLXSCDQXCBBTJFQZFSLTJBTKQBXXJJLJCHCZDBZJDCZJDCPRNPQCJPFCZLCLZXZDMXMPHJSGZ",
  171. "GSZZQLYLWTJPFSYASMCJBTZYYCWMYTZSJJLJCQLWZMALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNNSZFDEQFHBS",
  172. "AQTGYLBXMMYGSZLDYDQMJJRGBJTKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ",
  173. );
  174. function utf8_to_gbk($string)//编码转换,必须转换成GB2312字符,这里只是简单的判断并不是很准确,可以自己写一个.
  175. {
  176. return mb_convert_encoding($string,'gb2312','utf-8');
  177. }
  178. function conv($str)
  179. {
  180. $str = self::utf8_to_gbk($str);
  181. $len = strlen($str);
  182. $newStr = '';
  183. for($i=0; $i<$len ; ++$i)
  184. {
  185. $H = ord($str[$i]);
  186. $L = ord($str[$i+1]);
  187. //字符集非法
  188. if ($H < 0xB0 || $L < 0xA1 || $H > 0xF7 || $L == 0xFF)
  189. {
  190. $newStr .= $str[$i];
  191. continue;
  192. }
  193. if ($H < 0xD8)//($H >= 0xB0 && $H <=0xD7)//查询文字在一级汉字区(16-55)
  194. {
  195. $W = ($H << 8) | $L;
  196. foreach(self::$FirstTable as $key=>$value)
  197. {
  198. if ($W < $value)
  199. {
  200. $newStr .= self::$FirstLetter[$key];
  201. break;
  202. }
  203. }
  204. }
  205. else// if (H >= 0xD8 && H <= 0xF7)//查询中文在二级汉字区(56-87)
  206. $newStr .=self::$SecondTable[$H - 0xD8][$L-0xA1];
  207. ++$i;
  208. }
  209. return $newStr;
  210. }
  211. }