PageRenderTime 131ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/testSource/phpcms/content/application/controllers/news_album.php

https://gitlab.com/loda.sun.suryani/qijiatuku
PHP | 926 lines | 884 code | 15 blank | 27 comment | 31 complexity | f9833ce249c23815c013542e63dd49bb MD5 | raw file
  1. <?php
  2. if (! defined ( 'BASEPATH' ))
  3. exit ( 'No direct script access allowed' );
  4. class News_album extends MY_Controller {
  5. function __construct() {
  6. parent::__construct ();
  7. $this->load->library ( 'form_validation' );
  8. $this->load->library ( 'datagrid' );
  9. $this->load->helper ( 'html' );
  10. $this->load->library ( 'editors' );
  11. $this->load->library ( 'session' );
  12. $this->load->helper ( "pagenav" );
  13. $this->load->library ( 'tgapi' );
  14. $this->url = 'public/resource';
  15. }
  16. function index() { //图集列表
  17. $UID = $this->session->userdata ( 'UID' );
  18. /*$success = validation_check ( $UID, "news_demension_index" );
  19. if (! $success) {
  20. msg ( "无权限:角色对权限操作key=news_demension_index", "", "message" );
  21. exit ();
  22. }*/
  23. $view_data = array ();
  24. $view_data ['pages_nav'] = '';
  25. $view_data ['main_grid'] = '';
  26. //=========列表=====================
  27. $page_size = 10;
  28. $total_num = 0;
  29. $page_num = $this->input->post ( 'page_num' );
  30. if ($page_num < 1) {
  31. $page_num = 1;
  32. }
  33. $sql_where = " WHERE 1=1";
  34. if ($this->input->post ( 'permission_name' )) {
  35. $permission_name = trim ( $this->input->post ( 'permission_name' ) );
  36. $sql_where = "$sql_where AND permission_name like '%$permission_name%' ";
  37. }
  38. $sql_count = "SELECT count(*) as tot FROM news_image_album $sql_where"; //取总数,用于分页
  39. $row = $this->db->get_record_by_sql ( $sql_count, 'num' );
  40. $total_num = $row [0]; //取得总数
  41. $pages_obj = new PageNav ( $page_size, $total_num, $page_num, 10, 2 );
  42. $view_data ['pages_nav'] = $pages_obj->show_pages ();
  43. $select_limit_start = intval ( ($page_num - 1) * $page_size );
  44. $sql = "SELECT * FROM news_image_album $sql_where ORDER BY ab_id DESC";
  45. $sql = "$sql LIMIT {$select_limit_start},{$page_size}";
  46. $data = $this->db->get_rows_by_sql ( $sql );
  47. $field_list = trim ( "none" ); //这些字段才会出现在表格中
  48. $field_arr = null;
  49. if ($field_list) {
  50. $field_arr = explode ( ',', $field_list );
  51. $field_arr = array_flip ( $field_arr );
  52. }
  53. if (count ( $data )) {
  54. foreach ( $data as $k => $row ) {
  55. if ($field_arr) {
  56. $data [$k] = array_intersect_key ( $row, $field_arr );
  57. }
  58. $demension_id = $row ['ab_id']; //图集id
  59. $data [$k] ['id'] = $row ['ab_id'];
  60. $data [$k] ['标题'] = $row ['ab_title'];
  61. if ($row ['img_cover_url']) {
  62. if ($row ['img_cover_width'] && $row ['img_cover_width'] < 300) {
  63. $img_cover = "<img src={$row ['img_cover_url']}>";
  64. } else {
  65. $img_cover = "<img src={$row ['img_cover_url']} width=\"300\">";
  66. }
  67. } else {
  68. $sql = "SELECT*FROM news_image WHERE img_ab_id='$demension_id'limit 1"; //取总数,用于分页
  69. $imgs = $this->db->get_record_by_sql ( $sql );
  70. if (count ( $imgs )) {
  71. if ($imgs ['img_width'] && $imgs ['img_width'] < 300) {
  72. $img_cover = "<img src={$imgs['img_url']}/>";
  73. } else {
  74. $img_cover = "<img src={$imgs['img_url']} width=\"300\">";
  75. }
  76. } elseif (! count ( $imgs )) {
  77. $img_cover = "暂无封面";
  78. }
  79. }
  80. $data [$k] ['封面'] = $img_cover;
  81. $data [$k] ['标签'] = $this->tags ( $row ['ab_tags'] );
  82. $data [$k] ['操作'] = " <a href = \"javascript void(0)\" onclick=\"tuku($demension_id);return false;\">图库内容</a>";
  83. $data [$k] ['操作'] .= "<font color = \"blue\">&nbsp;|&nbsp;</font>";
  84. $data [$k] ['操作'] .= "<a href = \"javascript void(0)\" onclick=\"authorized($demension_id);return false;\">编辑</a>";
  85. $data [$k] ['操作'] .= "<font color = \"blue\">&nbsp;|&nbsp;</font>";
  86. $data [$k] ['操作'] .= "<a href = \"javascript void(0)\" onclick=\"if(!confirm('确定要删除?')){return false;}masterdel({$demension_id});return false;\">删除</a>";
  87. }
  88. $this->datagrid->reset ();
  89. $view_data ['main_grid'] = $this->datagrid->build ( 'datagrid', $data, TRUE );
  90. }
  91. $this->load->view ( 'tuku/news_album_view', $view_data );
  92. }
  93. function add() { //创建图库
  94. $UID = $this->session->userdata ( 'UID' );
  95. $TG_user_name = $this->session->userdata ( 'TG_user_name' );
  96. $TG_checkKey = $this->session->userdata ( 'TG_checkKey' );
  97. $view_data = array ();
  98. //添加图库
  99. $this->form_validation->set_rules ( 'ab_title', '标题', 'required' );
  100. $this->form_validation->set_rules ( 'ab_tags', '分类', 'required' );
  101. if ($this->form_validation->run () == TRUE) {
  102. $ab_title = trim ( $this->input->post ( 'ab_title' ) );
  103. $ab_tags = trim ( $this->input->post ( 'ab_tags' ) );
  104. $img_cover_url = $this->input->post ( 'img_url' );
  105. $img_cover_width = $this->input->post ( 'img_width' );
  106. $img_cover_heigth = $this->input->post ( 'img_heigth' );
  107. $ab_description = trim ( $this->input->post ( 'ab_description' ) );
  108. $is_mark = intval ( $this->input->post ( 'is_mark' ) );
  109. $water_img_id = intval ( $this->input->post ( 'water_img_id' ) );
  110. $water_img_pos = intval ( $this->input->post ( 'water_img_pos' ) );
  111. $data = array (
  112. 'ab_title' => $ab_title,
  113. 'ab_tags' => $ab_tags,
  114. 'img_cover_url' => $img_cover_url,
  115. 'img_cover_width' => $img_cover_width,
  116. 'img_cover_heigth' => $img_cover_heigth,
  117. 'create_time' => time (),
  118. 'modify_time' => time (),
  119. 'ab_description' => $ab_description );
  120. $ret = $this->db->insert ( "news_image_album", $data );
  121. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  122. }
  123. //==================调用水印图片================
  124. $view_data ['watermark'] = array ();
  125. $watermark = $this->db->get_rows_by_sql ( "select*from cms_watermark where is_temp = 0" );
  126. $view_data ['watermark'] = $watermark;
  127. //============================================
  128. //编辑器
  129. $eddt = array (
  130. 'id' => 'ab_description',
  131. 'value' => '',
  132. 'width' => '600px',
  133. 'height' => '200px' );
  134. $view_data ['ab_description'] = $this->editors->getedit ( $eddt );
  135. $view_data ['UID'] = $UID;
  136. $view_data ['TG_loginuser'] = base64_encode ( $TG_user_name );
  137. $view_data ['TG_checkKey'] = $TG_checkKey;
  138. //---选择器=-控制分类-
  139. $this->load->model ( 'tag_model' );
  140. $data = null;
  141. $data .= $this->tag_model->build_tag_select ( 'tagselector',
  142. array (8, 9, 10, 11, 12, 13, 14 ), null, 'ab_tags' );
  143. $data .= "<style>.selected {border-bottom:1px solid #ff0000;color:red;}
  144. .tag_dimen{color:blue;}
  145. #tagselector {border:1px solid #f0f0f0;padding:6px;}
  146. #div{border:1px solid #f0f0f0;margin:2px;padding:1px;}
  147. #span{border:1px solid #909090;margin:2px;padding:1px;}
  148. </style>";
  149. $view_data ['data_tag'] = $data;
  150. //上传控件
  151. $this->load->library ( 'editors' );
  152. $api_pic = modify_build_url (
  153. array (
  154. 'c' => 'news_album',
  155. 'm' => 'upload',
  156. 'type' => 'single',
  157. 'TG_loginuserid' => $UID,
  158. 'TG_loginuser' => base64_encode ( $TG_user_name ),
  159. 'TG_checkKey' => $TG_checkKey ) );
  160. $pic = array ('element_id' => 'img_cover_upload', 'script' => $api_pic, 'lable' => "false" );
  161. $view_data ['upload_img_over'] = $this->editors->get_upload ( $pic, 'uploadify' );
  162. $this->load->view ( 'tuku/news_album_add_view', $view_data );
  163. }
  164. function addtuku() { //图库批量上传图片
  165. $UID = $this->session->userdata ( 'UID' );
  166. $TG_user_name = $this->session->userdata ( 'TG_user_name' );
  167. $TG_checkKey = $this->session->userdata ( 'TG_checkKey' );
  168. $ab_id = intval ( $this->input->get ( 'ab_id' ) );
  169. $view_data = array ();
  170. $view_data ['ab_id'] = $ab_id;
  171. $record = $this->db->get_rows_by_sql (
  172. "select(img_id)from news_image where img_ab_id=$ab_id and length(img_url)>0" );
  173. $record_num = count ( $record );
  174. //添加图库
  175. $this->form_validation->set_rules ( 'img_tags', 'img_tags', 'required' );
  176. if ($this->form_validation->run () == TRUE) {
  177. $ab_title = trim ( $this->input->post ( 'ab_title' ) );
  178. $ab_tags = trim ( $this->input->post ( 'img_tags' ) );
  179. $img_description = trim ( $this->input->post ( 'img_description' ) );
  180. $img_url = $this->input->post ( 'img_url' );
  181. $img_width = $this->input->post ( 'img_width' );
  182. $img_heigth = $this->input->post ( 'img_heigth' );
  183. if (count ( $img_url )) {
  184. $num = $record_num + count ( $img_url );
  185. foreach ( $img_url as $k => $v ) {
  186. $img = array (
  187. 'img_url' => $v,
  188. 'img_width' => $img_width [$k],
  189. 'img_heigth' => $img_heigth [$k],
  190. 'img_tags' => $ab_tags,
  191. 'img_ab_id' => $ab_id,
  192. 'img_is_cover' => 0,
  193. 'img_seq' => $record_num + $k + 1,
  194. 'img_description' => $img_description );
  195. $db_ret = $this->db->insert ( "news_image", $img );
  196. }
  197. $this->db->where ( 'ab_id', $ab_id );
  198. $this->db->update ( 'news_image_album', array ('img_num' => $num ) );
  199. }
  200. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  201. }
  202. //==================调用水印图片================
  203. $view_data ['watermark'] = array ();
  204. $watermark = $this->db->get_rows_by_sql ( "select*from cms_watermark where is_temp = 0" );
  205. $view_data ['watermark'] = $watermark;
  206. //============================================
  207. //编辑器
  208. $eddt = array (
  209. 'id' => 'img_description',
  210. 'value' => '',
  211. 'width' => '600px',
  212. 'height' => '200px' );
  213. $view_data ['ab_description'] = $this->editors->getedit ( $eddt );
  214. $view_data ['UID'] = $UID;
  215. $view_data ['TG_loginuser'] = base64_encode ( $TG_user_name );
  216. $view_data ['TG_checkKey'] = $TG_checkKey;
  217. //---选择器=-控制分类-
  218. $this->load->model ( 'tag_model' );
  219. $data = null;
  220. $data .= $this->tag_model->build_tag_select ( 'tagselector',
  221. array (8, 9, 10, 11, 12, 13, 14, 15 ), null, 'img_tags' );
  222. $data .= "<style>.selected {border-bottom:1px solid #ff0000;color:red;}
  223. .tag_dimen{color:blue;}
  224. #tagselector {border:1px solid #f0f0f0;padding:6px;}
  225. #div{border:1px solid #f0f0f0;margin:2px;padding:1px;}
  226. #span{border:1px solid #909090;margin:2px;padding:1px;}</style>";
  227. $view_data ['data_tag'] = $data;
  228. //上传控件
  229. $this->load->library ( 'editors' );
  230. $data_url_pic = modify_build_url (
  231. array (
  232. 'c' => 'news_album',
  233. 'm' => 'upload',
  234. 'type' => 'more',
  235. 'TG_loginuserid' => $UID,
  236. 'TG_loginuser' => base64_encode ( $TG_user_name ),
  237. 'TG_checkKey' => $TG_checkKey ) );
  238. $pic = array (
  239. 'element_id' => 'custom_file_upload',
  240. 'script' => $data_url_pic,
  241. 'lable' => "false" );
  242. $view_data ['upload_file'] = $this->editors->get_upload ( $pic, 'more_uploadify' );
  243. $this->load->view ( 'tuku/news_album_addtuku_view', $view_data );
  244. }
  245. function tuku() { //图库内容列表
  246. $UID = $this->session->userdata ( 'UID' );
  247. $TG_user_name = $this->session->userdata ( 'TG_user_name' );
  248. $TG_checkKey = $this->session->userdata ( 'TG_checkKey' );
  249. $ab_id = trim ( $this->input->get ( 'ab_id' ) );
  250. $ab_id = intval ( $ab_id );
  251. $view_data = array ();
  252. $view_data ['pages_nav'] = '';
  253. $view_data ['main_grid'] = '';
  254. $view_data ['ab_id'] = $ab_id;
  255. //=========列表=====================
  256. $page_size = 10;
  257. $total_num = 0;
  258. $page_num = intval ( $this->input->post ( 'page_num' ) );
  259. if ($page_num < 1) {
  260. $page_num = 1;
  261. }
  262. $sql_where = " WHERE img_ab_id=$ab_id";
  263. if ($this->input->post ( 'permission_name' )) {
  264. $permission_name = trim ( $this->input->post ( 'permission_name' ) );
  265. $sql_where = "$sql_where AND permission_name like '%$permission_name%' ";
  266. }
  267. $sql_count = "SELECT count(*) as tot FROM news_image $sql_where"; //取总数,用于分页
  268. $row = $this->db->get_record_by_sql ( $sql_count, 'num' );
  269. $total_num = $row [0]; //取得总数
  270. $pages_obj = new PageNav ( $page_size, $total_num, $page_num, 10, 2 );
  271. $view_data ['pages_nav'] = $pages_obj->show_pages ();
  272. $select_limit_start = intval ( ($page_num - 1) * $page_size );
  273. $sql = "SELECT * FROM news_image $sql_where ORDER BY img_seq DESC";
  274. $sql = "$sql LIMIT {$select_limit_start},{$page_size}";
  275. $data = $this->db->get_rows_by_sql ( $sql );
  276. $field_list = trim ( "none" ); //这些字段才会出现在表格中
  277. $field_arr = null;
  278. if ($field_list) {
  279. $field_arr = explode ( ',', $field_list );
  280. $field_arr = array_flip ( $field_arr );
  281. //my_debug($field_arr);
  282. }
  283. if (count ( $data )) {
  284. foreach ( $data as $k => $row ) {
  285. if ($field_arr) {
  286. $data [$k] = array_intersect_key ( $row, $field_arr );
  287. }
  288. $img_id = $row ['img_id'];
  289. $img_ab_id = $row ['img_ab_id'];
  290. $data [$k] ['id'] = $img_id;
  291. if ($row ['img_width'] && $row ['img_width'] < 300) {
  292. $img_info = "<img src={$row['img_url']}/>";
  293. } else {
  294. $img_info = "<img src={$row['img_url']} width=\"300\"/>";
  295. }
  296. $data [$k] ['图片'] = $img_info;
  297. $data [$k] ['标签'] = $this->tags ( $row ['img_tags'] );
  298. $data [$k] ['描述'] = $row ['img_description'];
  299. $data [$k] ['排序'] = "";
  300. $data [$k] ['排序'] .= "<a href=\"javascript void(0)\" onclick=\"img_move_up({$row['img_id']},{$row['img_ab_id']});return false;\">上移</a>";
  301. $data [$k] ['排序'] .= "<font color = \"blue\">&nbsp;|&nbsp;</font>";
  302. $data [$k] ['排序'] .= "<a href=\"javascript void(0)\" onclick=\"img_move_down({$row['img_id']},{$row['img_ab_id']});return false;\">下移</a>";
  303. //$data [$k] ['排序'] .= $row['img_seq'];
  304. $data [$k] ['操作'] = "";
  305. if ($row ['img_is_cover'] == 1) {
  306. $data [$k] ['操作'] .= "<font color=red>设为封面图</font>";
  307. } else {
  308. $data [$k] ['操作'] .= " <a href = \"javascript void(0)\" onclick=\"tuku_f($img_id,$img_ab_id);return false;\">设为封面图</a>";
  309. }
  310. $data [$k] ['操作'] .= "<font color = \"blue\">&nbsp;|&nbsp;</font>";
  311. $data [$k] ['操作'] .= "<a href = \"javascript void(0)\" onclick=\"tuku_e($img_id);return false;\">编辑</a>";
  312. $data [$k] ['操作'] .= "<font color = \"blue\">&nbsp;|&nbsp;</font>";
  313. $data [$k] ['操作'] .= "<a href = \"javascript void(0)\" onclick=\"if(!confirm('确定要删除?'))return false;masterdel({$img_id},{$img_ab_id});return false;\"\">刪除</a>";
  314. }
  315. $this->datagrid->reset ();
  316. $view_data ['main_grid'] = $this->datagrid->build ( 'datagrid', $data, TRUE );
  317. }
  318. //=========列表=====================
  319. //添加图库
  320. $this->form_validation->set_rules ( 'ab_title', 'ab_title', 'required' );
  321. if ($this->form_validation->run () == TRUE) {
  322. $ab_title = trim ( $this->input->post ( 'ab_title' ) );
  323. $ab_tags = trim ( $this->input->post ( 'ab_tags' ) );
  324. $img_url = $this->input->post ( 'img_url' );
  325. $ab_description = trim ( $this->input->post ( 'ab_description' ) );
  326. $data = array (
  327. 'ab_title' => $ab_title,
  328. 'ab_tags' => $ab_tags,
  329. 'ab_description' => $ab_description );
  330. $ab_id = $this->db->insert ( "news_image_album", $data );
  331. if (count ( $api )) {
  332. foreach ( $api as $v ) {
  333. $img = array (
  334. 'img_addr' => $v,
  335. 'img_tags' => $ab_tags,
  336. 'img_ab_id' => $ab_id,
  337. 'img_is_cover' => 0,
  338. 'img_description' => '' );
  339. $db_ret = $this->db->insert ( "news_image", $img );
  340. //my_debug ( $img );
  341. }
  342. }
  343. //my_debug ( $api );
  344. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  345. }
  346. //编辑器
  347. $eddt = array (
  348. 'id' => 'ab_description',
  349. 'value' => '',
  350. 'width' => '600px',
  351. 'height' => '300px' );
  352. $view_data ['ab_description'] = $this->editors->getedit ( $eddt );
  353. $view_data ['UID'] = $UID;
  354. $view_data ['TG_loginuser'] = base64_encode ( $TG_user_name );
  355. $view_data ['TG_checkKey'] = $TG_checkKey;
  356. $this->load->view ( 'tuku/news_album_tuku_view', $view_data );
  357. }
  358. function bulk_edit() { //批量编辑图片描述
  359. $img_ab_id = intval ( $this->input->get ( 'ab_id' ) );
  360. $sql = "select*from news_image where img_ab_id=" . $img_ab_id;
  361. $img_rows = $this->db->get_rows_by_sql ( $sql );
  362. $view_data = array ();
  363. $view_data ['record'] = '';
  364. if (count ( $img_rows )) {
  365. foreach ( $img_rows as $k => $v ) {
  366. $img_rows [$k] ['img_tags'] = $this->tags ( $v ['img_tags'] );
  367. }
  368. $view_data ['img_rows'] = $img_rows;
  369. }
  370. $description = $this->input->post ( 'description' );
  371. if ($this->input->post ( 'submitform' )) {
  372. foreach ( $description as $k => $v ) {
  373. $this->db->where ( 'img_id', $k );
  374. $this->db->update ( 'news_image', array ('img_description' => $v [0] ) );
  375. }
  376. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  377. }
  378. $this->load->view ( 'tuku/news_img_bulkediting_view', $view_data );
  379. }
  380. function edit() { //编辑图库
  381. $UID = $this->session->userdata ( 'UID' );
  382. $TG_user_name = $this->session->userdata ( 'TG_user_name' );
  383. $TG_checkKey = $this->session->userdata ( 'TG_checkKey' );
  384. $ab_id = trim ( $this->input->get ( 'ab_id' ) );
  385. $ab_id = intval ( $ab_id );
  386. $view_data ['row'] = '';
  387. $persist_record = $this->db->get_record_by_field ( "news_image_album", 'ab_id', $ab_id );
  388. $view_data ['row'] = $persist_record;
  389. //my_debug($persist_record);
  390. //添加图库
  391. $this->form_validation->set_rules ( 'ab_title', 'ab_title', 'required' );
  392. $this->form_validation->set_rules ( 'ab_tags', 'ab_tags', 'required' );
  393. if ($this->form_validation->run () == TRUE) {
  394. $ab_tags = trim ( $this->input->post ( 'ab_tags' ) );
  395. $ab_title = $this->input->post ( 'ab_title' );
  396. $ab_description = trim ( $this->input->post ( 'ab_description' ) );
  397. if ($this->input->post ( 'img_url' )) {
  398. $img_cover_url = $this->input->post ( 'img_url' );
  399. $img_cover_width = intval ( $this->input->post ( 'img_width' ) );
  400. $img_cover_heigth = intval ( $this->input->post ( 'img_heigth' ) );
  401. } else {
  402. $img_cover_url = $this->input->post ( 'img_url_record' );
  403. $img_cover_width = intval ( $this->input->post ( 'img_width_record' ) );
  404. $img_cover_heigth = intval ( $this->input->post ( 'img_heigth_record' ) );
  405. }
  406. $img = array (
  407. 'ab_title' => $ab_title,
  408. 'ab_tags' => $ab_tags,
  409. 'img_cover_url' => $img_cover_url,
  410. 'img_cover_width' => $img_cover_width,
  411. 'img_cover_heigth' => $img_cover_heigth,
  412. 'ab_description' => $ab_description,
  413. 'modify_time' => time () );
  414. $this->db->where ( 'ab_id', $ab_id );
  415. $db_ret = $this->db->update ( "news_image_album", $img );
  416. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  417. }
  418. //==================调用水印图片================
  419. $view_data ['watermark'] = array ();
  420. $watermark = $this->db->get_rows_by_sql ( "select*from cms_watermark where is_temp = 0" );
  421. $view_data ['watermark'] = $watermark;
  422. //============================================
  423. //编辑器
  424. $eddt = array (
  425. 'id' => 'ab_description',
  426. 'value' => $persist_record ['ab_description'],
  427. 'width' => '600px',
  428. 'height' => '200px' );
  429. $view_data ['ab_description'] = $this->editors->getedit ( $eddt );
  430. //---选择器=-控制分类-
  431. $ab_tags_array = explode ( ",",
  432. str_replace ( "c", "", $persist_record ['ab_tags'] ) );
  433. $this->load->model ( 'tag_model' );
  434. $data = null;
  435. $data .= $this->tag_model->build_tag_select ( 'tagselector',
  436. array (8, 9, 10, 11, 12, 13, 14, 15 ), $ab_tags_array, 'ab_tags' );
  437. $data .= "<style>.selected {border-bottom:1px solid #ff0000;color:red;}
  438. .tag_dimen{color:blue;}
  439. #tagselector {border:1px solid #f0f0f0;padding:6px;}
  440. #div{border:1px solid #f0f0f0;margin:2px;padding:1px;}
  441. #span{border:1px solid #909090;margin:2px;padding:1px;}
  442. </style>";
  443. $view_data ['data_tag'] = $data;
  444. //上传控件
  445. $this->load->library ( 'editors' );
  446. $api_pic = modify_build_url (
  447. array (
  448. 'c' => 'news_album',
  449. 'm' => 'upload',
  450. 'type' => 'single',
  451. 'TG_loginuserid' => $UID,
  452. 'TG_loginuser' => base64_encode ( $TG_user_name ),
  453. 'TG_checkKey' => $TG_checkKey ) );
  454. $pic = array ('element_id' => 'img_cover_upload', 'script' => $api_pic, 'lable' => "false" );
  455. $view_data ['upload_img_over'] = $this->editors->get_upload ( $pic, 'uploadify' );
  456. $this->load->view ( 'tuku/news_album_edit_view', $view_data );
  457. }
  458. function cover() {
  459. $img_id = intval ( $this->input->get ( 'img_id' ) );
  460. $ab_id = intval ( $this->input->get ( 'ab_id' ) );
  461. $record = $this->db->get_record_by_sql ( "select*from news_image where img_id=$img_id " );
  462. $img_cover = array (
  463. 'img_cover_url' => $record ['img_url'],
  464. 'img_cover_width' => $record ['img_width'],
  465. 'img_cover_heigth' => $record ['img_heigth'] );
  466. $this->db->where ( 'img_ab_id', $ab_id );
  467. $this->db->update ( "news_image", array ('img_is_cover' => 0 ) );
  468. $this->db->where ( 'img_id', $img_id );
  469. $this->db->update ( "news_image", array ('img_is_cover' => 1 ) );
  470. $this->db->where ( 'ab_id', $ab_id );
  471. $this->db->update ( 'news_image_album', $img_cover );
  472. return;
  473. }
  474. function edit_img() { //编辑单张图片
  475. $UID = $this->session->userdata ( 'UID' );
  476. $TG_user_name = $this->session->userdata ( 'TG_user_name' );
  477. $TG_checkKey = $this->session->userdata ( 'TG_checkKey' );
  478. $img_id = trim ( $this->input->get ( 'img_id' ) );
  479. $img_id = intval ( $img_id );
  480. $view_data ['row'] = '';
  481. $persist_record = $this->db->get_record_by_field ( "news_image", 'img_id', $img_id );
  482. if (count ( $persist_record )) {
  483. foreach ( $persist_record as $k => $v ) {
  484. $api = $this->tgapi->get_tg_api ();
  485. $api->load ( "upload" );
  486. $persist_record ['pic'] = $persist_record ['img_url'];
  487. }
  488. }
  489. $view_data ['row'] = $persist_record;
  490. $this->form_validation->set_rules ( 'img_tags', 'img_tags', 'required' );
  491. if ($this->form_validation->run () == TRUE) {
  492. $img_tags = trim ( $this->input->post ( 'img_tags' ) );
  493. $img_description = trim ( $this->input->post ( 'img_description' ) );
  494. if ($this->input->post ( 'img_url' )) {
  495. $img_url = $this->input->post ( 'img_url' );
  496. $img_width = intval ( $this->input->post ( 'img_width' ) );
  497. $img_heigth = intval ( $this->input->post ( 'img_heigth' ) );
  498. } else {
  499. $img_url = $this->input->post ( 'img_url_record' );
  500. $img_width = intval ( $this->input->post ( 'img_width_record' ) );
  501. $img_heigth = intval ( $this->input->post ( 'img_heigth_record' ) );
  502. }
  503. $img = array (
  504. 'img_url' => $img_url,
  505. 'img_width' => $img_width,
  506. 'img_heigth' => $img_heigth,
  507. 'img_tags' => $img_tags,
  508. 'img_is_cover' => 0,
  509. 'img_description' => $img_description );
  510. $this->db->where ( 'img_id', $img_id );
  511. $this->db->update ( "news_image", $img );
  512. echo "<script>if(parent.window.close_dialog){parent.window.close_dialog();}</script>";
  513. }
  514. //==================调用水印图片================
  515. $view_data ['watermark'] = array ();
  516. $watermark = $this->db->get_rows_by_sql ( "select*from cms_watermark where is_temp = 0" );
  517. $view_data ['watermark'] = $watermark;
  518. //============================================
  519. //编辑器
  520. $eddt = array (
  521. 'id' => 'img_description',
  522. 'value' => $persist_record ['img_description'],
  523. 'width' => '600px',
  524. 'height' => '200px' );
  525. $view_data ['ab_description'] = $this->editors->getedit ( $eddt );
  526. //图片上传控件
  527. $data_url_pic = modify_build_url (
  528. array (
  529. 'c' => 'news_album',
  530. 'm' => 'upload',
  531. 'type' => 'single',
  532. 'TG_loginuserid' => $UID,
  533. 'TG_loginuser' => base64_encode ( $TG_user_name ),
  534. 'TG_checkKey' => $TG_checkKey ) );
  535. $pic = array ('element_id' => 'edit_img', 'script' => $data_url_pic, 'lable' => "false" );
  536. $view_data ['upload_pic'] = $this->editors->get_upload ( $pic );
  537. //分类选择器-------------------------------------------------------
  538. $ab_tags_array = explode ( ",",
  539. str_replace ( "c", "", $persist_record ['img_tags'] ) );
  540. $this->load->model ( 'tag_model' );
  541. $data = null;
  542. $data .= $this->tag_model->build_tag_select ( 'tagselector',
  543. array (8, 9, 10, 11, 12, 13, 14, 15 ), $ab_tags_array, 'img_tags' );
  544. $data .= "<style>.selected {border-bottom:1px solid #ff0000;color:red;}
  545. .tag_dimen{color:blue;}
  546. #tagselector {border:1px solid #f0f0f0;padding:6px;}
  547. #div{border:1px solid #f0f0f0;margin:2px;padding:1px;}
  548. #span{border:1px solid #909090;margin:2px;padding:1px;}
  549. </style>
  550. ";
  551. $view_data ['data_tag'] = $data;
  552. $this->load->view ( 'tuku/news_img_tuku_view', $view_data );
  553. }
  554. function master_delete() { //删除图库
  555. $UID = $this->session->userdata ( 'UID' );
  556. /*$success = validation_check ( $UID, "news_demension_del" );
  557. if (! $success) {
  558. msg ( "无权限:删除权限/news_demension_del/", "", "message" );
  559. exit ();
  560. }*/
  561. $ab_id = intval ( $this->input->get ( "id" ) );
  562. $this->db->where ( 'ab_id', $ab_id );
  563. $this->db->delete ( 'news_image_album' );
  564. $this->db->where ( 'img_ab_id', $ab_id );
  565. $this->db->delete ( 'news_image' );
  566. return;
  567. }
  568. function tuku_delete() { //删除图片
  569. $UID = $this->session->userdata ( 'UID' );
  570. /*$success = validation_check ( $UID, "news_demension_del" );
  571. if (! $success) {
  572. msg ( "无权限:删除权限/news_demension_del/", "", "message" );
  573. exit ();
  574. }*/
  575. $img_id = intval ( $this->input->get ( 'img_id' ) );
  576. $ab_id = intval ( $this->input->get ( 'ab_id' ) );
  577. $img_record = $this->db->get_record_by_field ( 'news_image', 'img_id', $img_id );
  578. $img_seq = $img_record ['img_seq'];
  579. $this->db->where ( 'img_id', $img_id );
  580. $this->db->delete ( 'news_image' );
  581. $img_rows = $this->db->get_rows_by_sql (
  582. "select*from news_image where img_ab_id=$ab_id and length(img_url)>0 and img_seq >" . $img_seq );
  583. foreach ( $img_rows as $k => $v ) {
  584. $new_img_seq = $v ['img_seq'] - 1;
  585. $this->db->where ( 'img_id', $v ['img_id'] );
  586. $this->db->update ( 'news_image', array ('img_seq' => $new_img_seq ) );
  587. }
  588. $record = $this->db->get_rows_by_sql (
  589. "select*from news_image where img_ab_id=$ab_id and length(img_url)>0" );
  590. $record_num = count ( $record );
  591. $this->db->where ( 'ab_id', $ab_id );
  592. $this->db->update ( 'news_image_album', array ('img_num' => $record_num ) );
  593. return;
  594. }
  595. function upload() { //图片上传
  596. $api = $this->tgapi->get_tg_api ();
  597. $api->load ( "upload" );
  598. //上传图片到cms服务器
  599. $is_mark = intval ( $this->input->get ( 'is_mark' ) ); //是否上水印
  600. $is_mark = 0;
  601. $water_img_id = intval ( $this->input->get ( 'water_img_id' ) ); //水印图片id
  602. $water_img_id = 5;
  603. $warter_img_pos = intval ( $this->input->get ( 'water_img_pos' ) ); //水印位置
  604. $water_img_id = 9;
  605. $type = $this->input->get ( 'type' ); //上传类型 单图为 single 多图为more
  606. $temp_name = $_FILES ['Filedata'] ['tmp_name'];
  607. $file_name = $_FILES ['Filedata'] ['name'];
  608. $file_name_parts = explode ( '.', $file_name );
  609. $len = count ( $file_name_parts );
  610. $file_ext_name = strtolower ( $file_name_parts [$len - 1] );
  611. $save_name = ("img" . "_" . time () . ".$file_ext_name");
  612. //确定保存的文件路径
  613. $path = sprintf ( "%spublic/resource/%s/", FCPATH, "watermark_temp" );
  614. create_dir ( $path );
  615. $targetfile = $path . $save_name;
  616. move_uploaded_file ( $temp_name, $targetfile );
  617. //对上传的图片进行水印等操作
  618. if ($is_mark && $is_mark == 1) {
  619. $water_img = $this->db->get_record_by_field ( 'cms_watermark', 'mark_id',
  620. $water_img_id );
  621. $water_img = FCPATH . $water_img ['mark_url'];
  622. $this->imageWaterMark ( $targetfile, $water_img_pos, $water_img ); //需要加水印图片、水印位置、水印图片
  623. }
  624. //将处理好的图片上传至图片服务器
  625. $img_info = getimagesize ( $targetfile );
  626. $width = $img_info [0];
  627. $heigth = $img_info [1];
  628. $new_file = $api->upload->from_files ( $targetfile );
  629. $url = $api->upload->get_url ( $new_file );
  630. unlink ( $targetfile );
  631. if ($type == 'single') {
  632. echo "<img src=$url><input value=$url type=hidden name=\"img_url\"/>
  633. <input value=$width type=hidden name=\"img_width\"/>
  634. <input value=$heigth type=hidden name=\"img_heigth\"/>";
  635. }
  636. if ($type == 'more') {
  637. echo "<img width=50 src=$url><input value=$url type=hidden name=\"img_url[]\">
  638. <input value=$width type=hidden name=\"img_width[]\"/>
  639. <input value=$heigth type=hidden name=\"img_heigth[]\"/>";
  640. }
  641. }
  642. function img_move_down() {
  643. $img_id = intval ( $this->input->get ( "img_id" ) );
  644. $img_ab_id = intval ( $this->input->get ( "ab_id" ) );
  645. //msg("$img_id","");
  646. $record = $this->db->get_record_by_field ( "news_image", 'img_id', $img_id );
  647. if ($img_ab_id == 0) {
  648. $sql = "SELECT * FROM news_image WHERE length(img_url)>0 ORDER BY img_seq DESC,img_id DESC";
  649. } else {
  650. $sql = "SELECT * FROM news_image WHERE length(img_url)>0 && img_ab_id={$record ['img_ab_id']} ORDER BY img_seq DESC,img_id DESC";
  651. }
  652. $sibling_arr = $this->db->get_rows_by_sql ( $sql );
  653. if (count ( $sibling_arr ) > 0) {
  654. foreach ( $sibling_arr as $k => $row ) {
  655. if ($row ['img_id'] == $img_id) {
  656. if ($k + 1 < count ( $sibling_arr )) {
  657. if ($img_ab_id == 0) {
  658. $next = $sibling_arr [$k + 1];
  659. $this->db->where ( 'img_id', $row ['img_id'] );
  660. $this->db->update ( 'news_image',
  661. array ('img_seq' => $next ['img_seq'] ) );
  662. $this->db->where ( 'img_id', $next ['img_id'] );
  663. $this->db->update ( 'news_image',
  664. array ('img_seq' => $row ['img_seq'] ) );
  665. } else {
  666. $next = $sibling_arr [$k + 1];
  667. $this->db->where ( 'img_id', $row ['img_id'] );
  668. $this->db->update ( 'news_image',
  669. array ('img_seq' => $next ['img_seq'] ) );
  670. $this->db->where ( 'img_id', $next ['img_id'] );
  671. $this->db->update ( 'news_image',
  672. array ('img_seq' => $row ['img_seq'] ) );
  673. }
  674. }
  675. }
  676. }
  677. }
  678. return;
  679. }
  680. function img_move_up() {
  681. $img_id = intval ( $this->input->get ( "img_id" ) );
  682. $img_ab_id = intval ( $this->input->get ( "ab_id" ) );
  683. $record = $this->db->get_record_by_field ( "news_image", 'img_id', $img_id );
  684. if ($img_ab_id != 0) {
  685. $sql = "SELECT * FROM news_image WHERE length(img_url)>0 && img_ab_id={$record ['img_ab_id']} ORDER BY img_seq DESC,img_id DESC";
  686. } else {
  687. $sql = "SELECT * FROM news_image WHERE length(course_url)>0 ORDER BY img_seq DESC,img_id DESC";
  688. }
  689. $sibling_arr = $this->db->get_rows_by_sql ( $sql );
  690. if (count ( $sibling_arr ) > 0) {
  691. foreach ( $sibling_arr as $k => $row ) {
  692. if ($row ['img_id'] == $img_id) {
  693. //存在前一条记录?
  694. if ($k > 0) {
  695. $pre = $sibling_arr [$k - 1];
  696. if ($img_ab_id != 0) {
  697. $this->db->where ( 'img_id', $row ['img_id'] );
  698. $this->db->update ( 'news_image',
  699. array ('img_seq' => $pre ['img_seq'] ) );
  700. $this->db->where ( 'img_id', $pre ['img_id'] );
  701. $this->db->update ( 'news_image',
  702. array ('img_seq' => $row ['img_seq'] ) );
  703. } else {
  704. $this->db->where ( 'img_id', $row ['img_id'] );
  705. $this->db->update ( 'news_image',
  706. array ('img_seq' => $pre ['img_seq'] ) );
  707. $this->db->where ( 'img_id', $pre ['img_id'] );
  708. $this->db->update ( 'news_image',
  709. array ('img_seq' => $row ['img_seq'] ) );
  710. }
  711. }
  712. }
  713. }
  714. }
  715. return;
  716. }
  717. private function imageWaterMark($groundImage, $waterPos = 0, $waterImage = "", $waterText = "",
  718. $textFont = 5, $textColor = "#FF0000") { //给图片添加水印(原图,位置,水印图,水印文字)
  719. $isWaterImage = FALSE;
  720. $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
  721. //读取水印文件
  722. if (file_exists ( $waterImage )) {
  723. $isWaterImage = TRUE;
  724. $water_info = getimagesize ( $waterImage );
  725. $water_w = $water_info [0]; //取得水印图片的宽
  726. $water_h = $water_info [1]; //取得水印图片的高
  727. switch ($water_info [2]) { //取得水印图片的格式
  728. case 1 :
  729. $water_im = imagecreatefromgif ( $waterImage );
  730. break;
  731. case 2 :
  732. $water_im = imagecreatefromjpeg ( $waterImage );
  733. break;
  734. case 3 :
  735. $water_im = imagecreatefrompng ( $waterImage );
  736. break;
  737. default :
  738. die ( $formatMsg );
  739. }
  740. }
  741. //读取背景图片
  742. if (file_exists ( $groundImage )) {
  743. $ground_info = getimagesize ( $groundImage );
  744. $ground_w = $ground_info [0]; //取得背景图片的宽
  745. $ground_h = $ground_info [1]; //取得背景图片的高
  746. switch ($ground_info [2]) { //取得背景图片的格式
  747. case 1 :
  748. $ground_im = imagecreatefromgif ( $groundImage );
  749. break;
  750. case 2 :
  751. $ground_im = imagecreatefromjpeg ( $groundImage );
  752. break;
  753. case 3 :
  754. $ground_im = imagecreatefrompng ( $groundImage );
  755. break;
  756. default :
  757. die ( $formatMsg );
  758. }
  759. } else {
  760. die ( "需要加水印的图片不存在!" );
  761. }
  762. //水印位置
  763. if ($isWaterImage) { //图片水印
  764. $w = $water_w;
  765. $h = $water_h;
  766. $label = "图片的";
  767. } else { //文字水印
  768. $temp = imagettfbbox ( ceil ( $textFont * 5 ), 0, "./cour.ttf", $waterText ); //取得使用 TrueType 字体的文本的范围
  769. $w = $temp [2] - $temp [6];
  770. $h = $temp [3] - $temp [7];
  771. unset ( $temp );
  772. $label = "文字区域";
  773. }
  774. if (($ground_w < $w) || ($ground_h < $h)) {
  775. echo "需要加水印的图片的长度或宽度比水印" . $label . "还小,无法生成水印!";
  776. return;
  777. }
  778. switch ($waterPos) {
  779. case 0 : //随机
  780. $posX = rand ( 0, ($ground_w - $w) );
  781. $posY = rand ( 0, ($ground_h - $h) );
  782. break;
  783. case 1 : //1为顶端居左
  784. $posX = 0;
  785. $posY = 0;
  786. break;
  787. case 2 : //2为顶端居中
  788. $posX = ($ground_w - $w) / 2;
  789. $posY = 0;
  790. break;
  791. case 3 : //3为顶端居右
  792. $posX = $ground_w - $w;
  793. $posY = 0;
  794. break;
  795. case 4 : //4为中部居左
  796. $posX = 0;
  797. $posY = ($ground_h - $h) / 2;
  798. break;
  799. case 5 : //5为中部居中
  800. $posX = ($ground_w - $w) / 2;
  801. $posY = ($ground_h - $h) / 2;
  802. break;
  803. case 6 : //6为中部居右
  804. $posX = $ground_w - $w;
  805. $posY = ($ground_h - $h) / 2;
  806. break;
  807. case 7 : //7为底端居左
  808. $posX = 0;
  809. $posY = $ground_h - $h;
  810. break;
  811. case 8 : //8为底端居中
  812. $posX = ($ground_w - $w) / 2;
  813. $posY = $ground_h - $h;
  814. break;
  815. case 9 : //9为底端居右
  816. $posX = $ground_w - $w;
  817. $posY = $ground_h - $h;
  818. break;
  819. default : //随机
  820. $posX = rand ( 0, ($ground_w - $w) );
  821. $posY = rand ( 0, ($ground_h - $h) );
  822. break;
  823. }
  824. //设定图像的混色模式
  825. imagealphablending ( $ground_im, true );
  826. if ($isWaterImage) { //图片水印
  827. imagecopy ( $ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h ); //拷贝水印到目标文件
  828. } else { //文字水印
  829. if (! emptyempty ( $textColor ) && (strlen ( $textColor ) == 7)) {
  830. $R = hexdec ( substr ( $textColor, 1, 2 ) );
  831. $G = hexdec ( substr ( $textColor, 3, 2 ) );
  832. $B = hexdec ( substr ( $textColor, 5 ) );
  833. } else {
  834. die ( "水印文字颜色格式不正确!" );
  835. }
  836. imagestring ( $ground_im, $textFont, $posX, $posY, $waterText,
  837. imagecolorallocate ( $ground_im, $R, $G, $B ) );
  838. }
  839. //生成水印后的图片
  840. unlink ( $groundImage );
  841. switch ($ground_info [2]) { //取得背景图片的格式
  842. case 1 :
  843. imagegif ( $ground_im, $groundImage );
  844. break;
  845. case 2 :
  846. imagejpeg ( $ground_im, $groundImage );
  847. break;
  848. case 3 :
  849. imagepng ( $ground_im, $groundImage );
  850. break;
  851. default :
  852. die ( $errorMsg );
  853. }
  854. //释放内存
  855. if (isset ( $water_info ))
  856. unset ( $water_info );
  857. if (isset ( $water_im ))
  858. imagedestroy ( $water_im );
  859. unset ( $ground_info );
  860. imagedestroy ( $ground_im );
  861. }
  862. private function tags($ab_tags) { //转换标签
  863. $tags_array = array ();
  864. $tags_vars = '';
  865. if ($ab_tags) {
  866. $tags_array = explode ( ",", str_replace ( "c", "", $ab_tags ) );
  867. foreach ( $tags_array as $row ) {
  868. $record = $this->db->get_record_by_field ( 'news_tag', 'tag_id', $row );
  869. $data [] = $record ['tag_name'];
  870. }
  871. $tags_vars = implode ( ',', $data );
  872. }
  873. return $tags_vars;
  874. }
  875. /*function tags_change($tag_vars) {
  876. $tag_id_vars = '';
  877. if ($tag_vars) {
  878. $tag_arr = explode ( ',', $tag_vars );
  879. foreach ( $tag_arr as $row ) {
  880. $record = $this->db->get_record_by_sql (
  881. "select ( tag_id ) from news_tag where tag_name = \"$row\" && tag_dimension_id = 15 " );
  882. $ids[] = "c".$record['tag_id']."c";
  883. }
  884. $ids_var = implode(',',$ids);
  885. }
  886. //my_debug($ids_var);
  887. return $ids_var;
  888. }*/
  889. }
  890. //end.