PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 2ms

/system/cp/cp.publish.php

https://github.com/danboy/Croissierd
PHP | 12868 lines | 9690 code | 2051 blank | 1127 comment | 1357 complexity | 0b20243405f78f6fdced90969332db15 MD5 | raw file
  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.publish.php
  15. -----------------------------------------------------
  16. Purpose: The main weblog class
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class Publish {
  24. var $assign_cat_parent = TRUE;
  25. var $direct_return = FALSE;
  26. var $categories = array();
  27. var $cat_parents = array();
  28. var $smileys = array();
  29. var $glossary = array();
  30. var $nest_categories = 'y';
  31. var $cat_array = array();
  32. var $SPELL = FALSE;
  33. var $comment_chars = 25;
  34. var $comment_leave_breaks = 'n';
  35. var $url_title_error = FALSE;
  36. var $installed_modules = array();
  37. /** ------------------------
  38. /** Request handler
  39. /** ------------------------*/
  40. function request_handler()
  41. {
  42. global $IN, $DSP, $LANG, $FNS, $PREFS, $DB;
  43. $this->assign_cat_parent = ($PREFS->ini('auto_assign_cat_parents') == 'n') ? FALSE : TRUE;
  44. $query = $DB->query("SELECT LOWER(module_name) as name FROM exp_modules");
  45. foreach($query->result as $row)
  46. {
  47. $this->installed_modules[$row['name']] = $row['name'];
  48. }
  49. switch ($IN->GBL('M'))
  50. {
  51. case 'new_entry' : ( ! $IN->GBL('preview', 'POST')) ? $this->submit_new_entry() : $this->new_entry_form('preview');
  52. break;
  53. case 'entry_form' : $this->new_entry_form();
  54. break;
  55. case 'edit_entry' : $this->new_entry_form('edit');
  56. break;
  57. case 'view_entry' : $this->view_entry();
  58. break;
  59. case 'view_entries' : $this->edit_entries();
  60. break;
  61. case 'multi_edit' : $this->multi_edit_form();
  62. break;
  63. case 'update_multi_entries' : $this->update_multi_entries();
  64. break;
  65. case 'entry_category_update': $this->multi_entry_category_update();
  66. break;
  67. case 'delete_conf' : $this->delete_entries_confirm();
  68. break;
  69. case 'delete_entries' : $this->delete_entries();
  70. break;
  71. case 'view_comments' : $this->view_comments();
  72. break;
  73. case 'view_trackbacks' : $this->view_trackbacks();
  74. break;
  75. case 'move_comments_form' : $this->move_comments_form();
  76. break;
  77. case 'move_comments' : $this->move_comments();
  78. break;
  79. case 'edit_comment' : $this->edit_comment_form();
  80. break;
  81. case 'edit_trackback' : $this->edit_trackback_form();
  82. break;
  83. case 'change_status' : $this->change_comment_status();
  84. break;
  85. case 'update_comment' : $this->update_comment();
  86. break;
  87. case 'update_trackback' : $this->update_trackback();
  88. break;
  89. case 'modify_comments' : $this->modify_comments();
  90. break;
  91. case 'del_comment_conf' : $this->delete_comment_confirm();
  92. break;
  93. case 'del_comment' : $this->delete_comment();
  94. break;
  95. case 'view_pings' : $this->view_previous_pings();
  96. break;
  97. case 'file_upload_form' : $this->file_upload_form();
  98. break;
  99. case 'upload_file' : $this->upload_file();
  100. break;
  101. case 'file_browser' : $this->file_browser();
  102. break;
  103. case 'replace_file' : $this->replace_file();
  104. break;
  105. case 'image_options' : $this->image_options_form();
  106. break;
  107. case 'create_thumb' : $this->create_thumb();
  108. break;
  109. case 'spellcheck_iframe' : $this->spellcheck_iframe();
  110. break;
  111. case 'spellcheck' : $this->spellcheck();
  112. break;
  113. case 'emoticons' : $this->emoticons();
  114. break;
  115. default :
  116. if ($IN->GBL('C') == 'publish')
  117. {
  118. if ($IN->GBL('BK'))
  119. {
  120. return $this->new_entry_form();
  121. }
  122. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  123. if (count($assigned_weblogs) == 0)
  124. {
  125. return $DSP->no_access_message($LANG->line('unauthorized_for_any_blogs'));
  126. }
  127. else
  128. {
  129. if (count($assigned_weblogs) == 1)
  130. {
  131. return $this->new_entry_form();
  132. }
  133. else
  134. {
  135. return $this->weblog_select_list();
  136. }
  137. }
  138. }
  139. else
  140. {
  141. return $this->edit_entries();
  142. }
  143. break;
  144. }
  145. }
  146. /* END */
  147. /** --------------------------------------------
  148. /** Weblog selection menu
  149. /** --------------------------------------------*/
  150. // This function shows a list of available weblogs.
  151. // This list will be displayed when a user clicks the
  152. // "publish" link when more than one weblog exist.
  153. //--------------------------------------------
  154. function weblog_select_list($add='')
  155. {
  156. global $IN, $DSP, $DB, $LANG, $FNS, $SESS;
  157. if ($IN->GBL('C') == 'publish')
  158. {
  159. $blurb = $LANG->line('select_blog_to_post_in');
  160. $title = $LANG->line('publish');
  161. $action = 'C=publish'.AMP.'M=entry_form';
  162. }
  163. else
  164. {
  165. $blurb = $LANG->line('select_blog_to_edit');
  166. $title = $LANG->line('edit');
  167. $action = 'C=edit'.AMP.'M=view_entries';
  168. }
  169. /** -------------------------------------------------
  170. /** Fetch the blogs the user is allowed to post in
  171. /** -------------------------------------------------*/
  172. $links = array();
  173. $i = 0;
  174. foreach ($SESS->userdata['assigned_weblogs'] as $weblog_id => $weblog_title)
  175. {
  176. $links[] = $DSP->table_qrow(($i++ % 2) ? 'tableCellOne' : 'tableCellTwo', $DSP->qdiv('defaultBold', $DSP->anchor(BASE.AMP.$action.AMP.'weblog_id='.$weblog_id.$add, $weblog_title)));
  177. }
  178. // If there are no allowed blogs, show a message
  179. if (count($links) < 1)
  180. {
  181. return $DSP->no_access_message($LANG->line('unauthorized_for_any_blogs'));
  182. }
  183. $DSP->body .= $DSP->table('tableBorder', '0', '', '100%')
  184. .$DSP->table_qrow('tableHeading', $blurb);
  185. foreach ($links as $val)
  186. {
  187. $DSP->body .= $val;
  188. }
  189. $DSP->body .= $DSP->table_c();
  190. $DSP->title = $title;
  191. $DSP->crumb = $title;
  192. }
  193. /* END */
  194. /** --------------------------------------------
  195. /** Weblog "new entry" form
  196. /** --------------------------------------------*/
  197. // This function displays the form used to submit, edit, or
  198. // preview new weblog entries with.
  199. //--------------------------------------------
  200. function new_entry_form($which = 'new', $submission_error = '', $entry_id='', $hidden = array())
  201. {
  202. global $DSP, $LANG, $LOC, $DB, $IN, $REGX, $FNS, $SESS, $PREFS, $EXT;
  203. $title = '';
  204. $url_title = '';
  205. $url_title_prefix = '';
  206. $default_entry_title = '';
  207. $status = '';
  208. $expiration_date = '';
  209. $comment_expiration_date = '';
  210. $entry_date = '';
  211. $sticky = '';
  212. $allow_trackbacks = '';
  213. $trackback_urls = '';
  214. $field_data = '';
  215. $allow_comments = '';
  216. $preview_text = '';
  217. $catlist = '';
  218. $author_id = '';
  219. $tb_url = '';
  220. $bookmarklet = FALSE;
  221. $version_id = $IN->GBL('version_id');
  222. $version_num = $IN->GBL('version_num');
  223. $dst_enabled = $SESS->userdata('daylight_savings');
  224. $weblog_id = '';
  225. if ($PREFS->ini('site_pages') !== FALSE)
  226. {
  227. $LANG->fetch_language_file('pages');
  228. }
  229. $publish_tabs = array('form' => $LANG->line('publish_form'),
  230. 'date' => $LANG->line('date'),
  231. 'cat' => $LANG->line('categories'),
  232. 'option' => $LANG->line('options'),
  233. 'tb' => $LANG->line('trackbacks'),
  234. 'ping' => $LANG->line('pings'),
  235. 'forum' => $LANG->line('forum'),
  236. 'revisions' => $LANG->line('revisions'),
  237. 'pages' => $LANG->line('pages_module_name'),
  238. 'show_all' => $LANG->line('show_all'),
  239. );
  240. /** ------------------------------------------------------------------
  241. /** We need to first determine which weblog to post the entry into.
  242. /** ------------------------------------------------------------------*/
  243. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  244. // if it's an edit, we just need the entry id and can figure out the rest
  245. if ($IN->GBL('entry_id', 'GET') !== FALSE AND is_numeric($IN->GBL('entry_id', 'GET')) AND $weblog_id == '')
  246. {
  247. $query = $DB->query("SELECT weblog_id FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($IN->GBL('entry_id', 'GET'))."'");
  248. if ($query->num_rows == 1)
  249. {
  250. $weblog_id = $query->row['weblog_id'];
  251. }
  252. }
  253. if ($weblog_id == '' AND ! ($weblog_id = $IN->GBL('weblog_id', 'GP')))
  254. {
  255. // Does the user have their own blog?
  256. if ($SESS->userdata['weblog_id'] != 0)
  257. {
  258. $weblog_id = $SESS->userdata['weblog_id'];
  259. }
  260. elseif (sizeof($assigned_weblogs) == 1)
  261. {
  262. $weblog_id = $assigned_weblogs['0'];
  263. }
  264. else
  265. {
  266. $query = $DB->query("SELECT weblog_id from exp_weblogs WHERE is_user_blog = 'n'");
  267. if ($query->num_rows == 1)
  268. {
  269. $weblog_id = $query->row['weblog_id'];
  270. }
  271. else
  272. {
  273. return false;
  274. }
  275. }
  276. }
  277. if ( ! is_numeric($weblog_id))
  278. return FALSE;
  279. /** ----------------------------------------------
  280. /** Security check
  281. /** ---------------------------------------------*/
  282. if ( ! in_array($weblog_id, $assigned_weblogs))
  283. {
  284. return $DSP->no_access_message($LANG->line('unauthorized_for_this_blog'));
  285. }
  286. // -------------------------------------------
  287. // 'publish_form_start' hook.
  288. // - Allows complete rewrite of Publish page.
  289. // - Added $hidden: 1.6.0
  290. //
  291. $edata = $EXT->call_extension('publish_form_start', $which, $submission_error, $entry_id, $hidden);
  292. if ($EXT->end_script === TRUE) return;
  293. //
  294. // -------------------------------------------
  295. // -------------------------------------------
  296. // 'publish_form_headers' hook.
  297. // - Adds content to headers for Publish page.
  298. // - Added $weblog_id: 1.6
  299. // - Added $hidden: 1.6.0
  300. //
  301. $DSP->extra_header .= $EXT->call_extension('publish_form_headers', $which, $submission_error, $entry_id, $weblog_id, $hidden);
  302. if ($EXT->end_script === TRUE) return;
  303. //
  304. // -------------------------------------------
  305. // -------------------------------------------
  306. // 'publish_form_new_tabs' hook.
  307. // - Allows adding of new tabs to submission form
  308. // - Added: 1.4.1
  309. // - Added $hidden: 1.6.0
  310. //
  311. if ($EXT->active_hook('publish_form_new_tabs') === TRUE)
  312. {
  313. $publish_tabs = $EXT->call_extension('publish_form_new_tabs', $publish_tabs, $weblog_id, $entry_id, $hidden);
  314. }
  315. //
  316. // -------------------------------------------
  317. /** ----------------------------------------------
  318. /** If Still Set, Show All Goes at the End
  319. /** ---------------------------------------------*/
  320. if (isset($publish_tabs['show_all']))
  321. {
  322. unset($publish_tabs['show_all']);
  323. $publish_tabs['show_all'] = $LANG->line('show_all');
  324. }
  325. /** ----------------------------------------------
  326. /** Fetch weblog preferences
  327. /** ---------------------------------------------*/
  328. $query = $DB->query("SELECT * FROM exp_weblogs WHERE weblog_id = '".$DB->escape_str($weblog_id)."'");
  329. if ($query->num_rows == 0)
  330. {
  331. return $DSP->error_message($LANG->line('no_weblog_exits'));
  332. }
  333. // -------------------------------------------
  334. // 'publish_form_weblog_preferences' hook.
  335. // - Modify weblog preferences
  336. // - Added: 1.4.1
  337. //
  338. if ($EXT->active_hook('publish_form_weblog_preferences') === TRUE)
  339. {
  340. $query->row = $EXT->call_extension('publish_form_weblog_preferences', $query->row);
  341. }
  342. //
  343. // -------------------------------------------
  344. foreach ($query->row as $key => $val)
  345. {
  346. $$key = $val;
  347. }
  348. /** ----------------------------------------------
  349. /** Fetch Revision if Necessary
  350. /** ---------------------------------------------*/
  351. $show_revision_cluster = ($enable_versioning == 'y') ? 'y' : 'n';
  352. if ($which == 'new')
  353. {
  354. $versioning_enabled = ($enable_versioning == 'y') ? 'y' : 'n';
  355. }
  356. else
  357. {
  358. $versioning_enabled = (isset($_POST['versioning_enabled'])) ? 'y' : 'n';
  359. }
  360. if (is_numeric($version_id))
  361. {
  362. $entry_id = $IN->GBL('entry_id');
  363. $revquery = $DB->query("SELECT version_data FROM exp_entry_versioning WHERE entry_id = '{$entry_id}' AND version_id = '{$version_id}'");
  364. if ($revquery->num_rows == 1)
  365. {
  366. $_POST = $REGX->array_stripslashes(@unserialize($revquery->row['version_data']));
  367. $_POST['entry_id'] = $entry_id;
  368. $which = 'preview';
  369. }
  370. unset($revquery);
  371. }
  372. /** ---------------------------------------
  373. /** Insane Idea to Have Defaults and Prefixes
  374. /** ---------------------------------------*/
  375. if ($which == 'edit')
  376. {
  377. $url_title_prefix = '';
  378. }
  379. elseif ($which == 'new')
  380. {
  381. $title = $default_entry_title;
  382. $url_title = $url_title_prefix;
  383. }
  384. // --------------------------------------------------------------------
  385. // The $which variable determines what the page should show:
  386. // If $which = 'new' we'll show a blank "new entry" page
  387. // If $which = "preview", the user has clicked the "preview" button.
  388. // If $which = "edit", we are editing an already existing entry.
  389. // If $which = 'save', like a preview, but also an edit.
  390. // --------------------------------------------------------------------
  391. if ($which == 'edit')
  392. {
  393. if ( ! $entry_id = $IN->GBL('entry_id', 'GET'))
  394. {
  395. return false;
  396. }
  397. // Fetch the weblog data
  398. $sql = "SELECT t.*, d.*
  399. FROM exp_weblog_titles AS t, exp_weblog_data AS d
  400. WHERE t.entry_id = '$entry_id'
  401. AND t.weblog_id = '$weblog_id'
  402. AND t.entry_id = d.entry_id";
  403. $result = $DB->query($sql);
  404. if ($result->num_rows == 0)
  405. {
  406. return $DSP->error_message($LANG->line('no_weblog_exits'));
  407. }
  408. if ($result->row['author_id'] != $SESS->userdata('member_id'))
  409. {
  410. if ( ! $DSP->allowed_group('can_edit_other_entries'))
  411. {
  412. return $DSP->no_access_message();
  413. }
  414. }
  415. // -------------------------------------------
  416. // 'publish_form_entry_data' hook.
  417. // - Modify entry's data
  418. // - Added: 1.4.1
  419. //
  420. if ($EXT->active_hook('publish_form_entry_data') === TRUE)
  421. {
  422. $result->row = $EXT->call_extension('publish_form_entry_data', $result->row);
  423. }
  424. //
  425. // -------------------------------------------
  426. foreach ($result->row as $key => $val)
  427. {
  428. $$key = $val;
  429. }
  430. }
  431. /** ---------------------------------------------
  432. /** Assign page title based on type of request
  433. /** ---------------------------------------------*/
  434. switch ($which)
  435. {
  436. case 'edit' : $DSP->title = $LANG->line('edit_entry');
  437. break;
  438. case 'save' : $DSP->title = $LANG->line('edit_entry');
  439. break;
  440. case 'preview' : $DSP->title = $LANG->line('preview');
  441. break;
  442. default : $DSP->title = $LANG->line('new_entry');
  443. break;
  444. }
  445. /** ----------------------------------------------
  446. /** Assign breadcrumb
  447. /** ---------------------------------------------*/
  448. $DSP->crumb = $DSP->title.$DSP->crumb_item($blog_title);
  449. $activate_calendars = '"';
  450. if ($show_date_menu == 'y')
  451. {
  452. // Setup some onload items
  453. $activate_calendars = 'activate_calendars();" ';
  454. $DSP->extra_header .= '<script type="text/javascript">
  455. // depending on timezones, local settings and localization prefs, its possible for js to misinterpret the day,
  456. // but the humanized time is correct, so we activate the humanized time to sync the calendar
  457. function activate_calendars() {
  458. update_calendar(\'entry_date\', document.getElementById(\'entry_date\').value);
  459. update_calendar(\'expiration_date\', document.getElementById(\'expiration_date\').value);';
  460. if ($comment_system_enabled == 'y')
  461. {
  462. $DSP->extra_header .= "\n\t\t\t\t".'update_calendar(\'comment_expiration_date\', document.getElementById(\'comment_expiration_date\').value);';
  463. }
  464. $DSP->extra_header .= "\n\t\t\t\t"."current_month = '';
  465. current_year = '';
  466. last_date = '';";
  467. $DSP->extra_header .= "\n".'}
  468. </script>';
  469. }
  470. /* -------------------------------------
  471. /* Publish Page Title Focus
  472. /*
  473. /* makes the title field gain focus when the page is loaded
  474. /*
  475. /* Hidden Configuration Variable
  476. /* - publish_page_title_focus => Set focus to the tile? (y/n)
  477. /* -------------------------------------*/
  478. if ($which != 'edit' && $PREFS->ini('publish_page_title_focus') !== 'n')
  479. {
  480. $load_events = 'document.forms[0].title.focus();set_catlink();';
  481. }
  482. else
  483. {
  484. $load_events = 'set_catlink();';
  485. }
  486. $DSP->body_props .= ' onload="'.$load_events.$activate_calendars;
  487. // -------------------------------------------
  488. // 'publish_form_body_props' hook.
  489. // - Allows setting of the body properties
  490. //
  491. $edata = $EXT->call_extension('publish_form_body_props');
  492. if ($EXT->end_script === TRUE) return;
  493. //
  494. // -------------------------------------------
  495. /** ----------------------------------------------
  496. /** Are we using the bookmarklet?
  497. /** ---------------------------------------------*/
  498. if ($IN->GBL('BK', 'GP'))
  499. {
  500. $bookmarklet = TRUE;
  501. $tb_url = $IN->GBL('tb_url', 'GP');
  502. }
  503. /** ----------------------------------------------
  504. /** Start building the page output
  505. /** ---------------------------------------------*/
  506. $r = '';
  507. /** ----------------------------------------------
  508. /** Form header and hidden fields
  509. /** ---------------------------------------------*/
  510. $BK = ($bookmarklet == TRUE) ? AMP.'BK=1'.AMP.'Z=1' : '';
  511. if ($IN->GBL('C') == 'publish')
  512. {
  513. $r .= $DSP->form_open(
  514. array(
  515. 'action' => 'C=publish'.AMP.'M=new_entry'.$BK,
  516. 'name' => 'entryform',
  517. 'id' => 'entryform'
  518. )
  519. );
  520. }
  521. else
  522. {
  523. $r .= $DSP->form_open(
  524. array(
  525. 'action' => 'C=edit'.AMP.'M=new_entry'.$BK,
  526. 'name' => 'entryform',
  527. 'id' => 'entryform'
  528. )
  529. );
  530. }
  531. $r .= $DSP->input_hidden('weblog_id', $weblog_id);
  532. foreach($hidden as $key => $value)
  533. {
  534. $r .= $DSP->input_hidden($key, $value);
  535. }
  536. if ($IN->GBL('entry_id', 'POST'))
  537. {
  538. $entry_id = $IN->GBL('entry_id');
  539. }
  540. if (isset($entry_id))
  541. {
  542. $r .= $DSP->input_hidden('entry_id', $entry_id);
  543. }
  544. if ($bookmarklet == TRUE)
  545. {
  546. $r .= $DSP->input_hidden('tb_url', $tb_url);
  547. }
  548. /** --------------------------------
  549. /** Fetch Custom Fields
  550. /** --------------------------------*/
  551. // Even though we don't need this query until laters we'll run the
  552. // query here so that we can show previews in the proper order.
  553. // -------------------------------------------
  554. // 'publish_form_field_query' hook.
  555. // - Allows control over the field query, controlling what fields will be displayed
  556. //
  557. if (isset($EXT->extensions['publish_form_field_query']))
  558. {
  559. $field_query = $EXT->call_extension('publish_form_field_query', $this, $field_group);
  560. }
  561. else
  562. {
  563. $field_query = $DB->query("SELECT * FROM exp_weblog_fields WHERE group_id = '$field_group' ORDER BY field_order");
  564. }
  565. //
  566. // -------------------------------------------
  567. /** ----------------------------------------------
  568. /** Javascript stuff
  569. /** ---------------------------------------------*/
  570. $convert_ascii = ($PREFS->ini('auto_convert_high_ascii') == 'y') ? TRUE : FALSE;
  571. // "title" input Field
  572. if ($IN->GBL('title', 'GET'))
  573. {
  574. $title = $this->bm_qstr_decode($IN->GBL('title', 'GET'));
  575. }
  576. $word_separator = $PREFS->ini('word_separator') != "dash" ? '_' : '-';
  577. if ( ! class_exists('Spellcheck'))
  578. {
  579. require PATH_CORE.'core.spellcheck'.EXT;
  580. }
  581. $this->SPELL = new Spellcheck();
  582. $spellcheck_js = $this->SPELL->JavaScript(BASE.'&C=publish&M=spellcheck');
  583. /** -------------------------------------
  584. /** Create Foreign Character Conversion JS
  585. /** -------------------------------------*/
  586. /* -------------------------------------
  587. /* 'foreign_character_conversion_array' hook.
  588. /* - Allows you to use your own foreign character conversion array
  589. /* - Added 1.6.0
  590. */
  591. if (isset($EXT->extensions['foreign_character_conversion_array']))
  592. {
  593. $foreign_characters = $EXT->call_extension('foreign_character_conversion_array');
  594. }
  595. else
  596. {
  597. $foreign_characters = array('223' => "ss", // ß
  598. '224' => "a", '225' => "a", '226' => "a", '229' => "a",
  599. '227' => "ae", '230' => "ae", '228' => "ae",
  600. '231' => "c",
  601. '232' => "e", // è
  602. '233' => "e", // é
  603. '234' => "e", // ê
  604. '235' => "e", // ë
  605. '236' => "i", '237' => "i", '238' => "i", '239' => "i",
  606. '241' => "n",
  607. '242' => "o", '243' => "o", '244' => "o", '245' => "o",
  608. '246' => "oe", // ö
  609. '249' => "u", '250' => "u", '251' => "u",
  610. '252' => "ue", // ü
  611. '255' => "y",
  612. '257' => "aa",
  613. '269' => "ch",
  614. '275' => "ee",
  615. '291' => "gj",
  616. '299' => "ii",
  617. '311' => "kj",
  618. '316' => "lj",
  619. '326' => "nj",
  620. '353' => "sh",
  621. '363' => "uu",
  622. '382' => "zh",
  623. '256' => "aa",
  624. '268' => "ch",
  625. '274' => "ee",
  626. '290' => "gj",
  627. '298' => "ii",
  628. '310' => "kj",
  629. '315' => "lj",
  630. '325' => "nj",
  631. '352' => "sh",
  632. '362' => "uu",
  633. '381' => "zh",
  634. );
  635. }
  636. /*
  637. /* -------------------------------------*/
  638. $foreign_replace = '';
  639. foreach($foreign_characters as $old => $new)
  640. {
  641. $foreign_replace .= "if (c == '$old') {NewTextTemp += '$new'; continue;}\n\t\t\t\t";
  642. }
  643. /** -------------------------------------
  644. /** Publish Tabs JavaScript
  645. /** -------------------------------------*/
  646. $publish_tabs_javascript = "var blockarray = new Array(".(sizeof($publish_tabs) - 1).")\n";
  647. $p = 0;
  648. foreach($publish_tabs as $short => $long)
  649. {
  650. $publish_tabs_javascript .= "\t\t".'blockarray['.$p.'] = "block'.$short.'"'."\n"; $p++;
  651. }
  652. $default_entry_title = $REGX->form_prep($default_entry_title);
  653. $r .= <<<EOT
  654. <script type="text/javascript">
  655. <!--
  656. /** ------------------------------------
  657. /** Swap out categories
  658. /** -------------------------------------*/
  659. // This is used by the "edit categories" feature
  660. function set_catlink()
  661. {
  662. if (document.getElementById('cateditlink'))
  663. {
  664. if (browser == "IE" && OS == "Mac")
  665. {
  666. document.getElementById('cateditlink').style.display = "none";
  667. }
  668. else
  669. {
  670. document.getElementById('cateditlink').style.display = "block";
  671. }
  672. }
  673. }
  674. function swap_categories(str)
  675. {
  676. document.getElementById('categorytree').innerHTML = str;
  677. }
  678. /** ------------------------------------
  679. /** Array Helper Functions
  680. /** -------------------------------------*/
  681. function getarraysize(thearray)
  682. {
  683. for (i = 0; i < thearray.length; i++)
  684. {
  685. if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
  686. {
  687. return i;
  688. }
  689. }
  690. return thearray.length;
  691. }
  692. // Array push
  693. function arraypush(thearray, value)
  694. {
  695. thearray[getarraysize(thearray)] = value;
  696. }
  697. // Array pop
  698. function arraypop(thearray)
  699. {
  700. thearraysize = getarraysize(thearray);
  701. retval = thearray[thearraysize - 1];
  702. delete thearray[thearraysize - 1];
  703. return retval;
  704. }
  705. /** ------------------------------------
  706. /** Live URL Title Function
  707. /** -------------------------------------*/
  708. function liveUrlTitle()
  709. {
  710. var defaultTitle = '{$default_entry_title}';
  711. var NewText = document.getElementById("title").value;
  712. if (defaultTitle != '')
  713. {
  714. if (NewText.substr(0, defaultTitle.length) == defaultTitle)
  715. {
  716. NewText = NewText.substr(defaultTitle.length);
  717. }
  718. }
  719. NewText = NewText.toLowerCase();
  720. var separator = "{$word_separator}";
  721. // Foreign Character Attempt
  722. var NewTextTemp = '';
  723. for(var pos=0; pos<NewText.length; pos++)
  724. {
  725. var c = NewText.charCodeAt(pos);
  726. if (c >= 32 && c < 128)
  727. {
  728. NewTextTemp += NewText.charAt(pos);
  729. }
  730. else
  731. {
  732. {$foreign_replace}
  733. }
  734. }
  735. var multiReg = new RegExp(separator + '{2,}', 'g');
  736. NewText = NewTextTemp;
  737. NewText = NewText.replace('/<(.*?)>/g', '');
  738. NewText = NewText.replace(/\s+/g, separator);
  739. NewText = NewText.replace(/\//g, separator);
  740. NewText = NewText.replace(/[^a-z0-9\-\._]/g,'');
  741. NewText = NewText.replace(/\+/g, separator);
  742. NewText = NewText.replace(multiReg, separator);
  743. NewText = NewText.replace(/-$/g,'');
  744. NewText = NewText.replace(/_$/g,'');
  745. NewText = NewText.replace(/^_/g,'');
  746. NewText = NewText.replace(/^-/g,'');
  747. NewText = NewText.replace(/\.+$/g,'');
  748. if (document.getElementById("url_title"))
  749. {
  750. document.getElementById("url_title").value = "{$url_title_prefix}" + NewText;
  751. }
  752. else
  753. {
  754. document.forms['entryform'].elements['url_title'].value = "{$url_title_prefix}" + NewText;
  755. }
  756. }
  757. /** ------------------------------------
  758. /** Publish Option Tabs Open/Close
  759. /** -------------------------------------*/
  760. {$publish_tabs_javascript}
  761. function showblock(which)
  762. {
  763. for (i = 0 ; i < blockarray.length; i++ )
  764. {
  765. if (document.getElementById(blockarray[i]))
  766. {
  767. if (which == 'blockshow_all')
  768. {
  769. document.getElementById(blockarray[i]).style.display = "block";
  770. }
  771. else
  772. {
  773. document.getElementById(blockarray[i]).style.display = "none";
  774. }
  775. }
  776. var menu = blockarray[i].substring(5) + 'menu';
  777. if (document.getElementById(menu))
  778. {
  779. document.getElementById(menu).style.display = "none";
  780. }
  781. }
  782. var menu = which.substring(5) + 'menu';
  783. if (document.getElementById(which))
  784. {
  785. document.getElementById(which).style.display = "block";
  786. document.getElementById(menu).style.display = "block";
  787. }
  788. }
  789. function styleswitch(link)
  790. {
  791. if (document.getElementById(link).className == 'publishTabs')
  792. {
  793. document.getElementById(link).className = 'publishTabsHover';
  794. }
  795. }
  796. function stylereset(link)
  797. {
  798. if (document.getElementById(link).className == 'publishTabsHover')
  799. {
  800. document.getElementById(link).className = 'publishTabs';
  801. }
  802. }
  803. /** ------------------------------------
  804. /** Glossary Item Insert
  805. /** -------------------------------------*/
  806. function glossaryInsert(item, id, tag)
  807. {
  808. selField = "field_id_" + id;
  809. taginsert('other', tag, '');
  810. }
  811. /** ------------------------------------
  812. /** Smiley Insert
  813. /** -------------------------------------*/
  814. function add_smiley(smiley, id)
  815. {
  816. selField = "field_id_" + id;
  817. taginsert('other', " " + smiley + " ", '');
  818. showhide_smileys(id);
  819. }
  820. {$spellcheck_js}
  821. /** ------------------------------------
  822. /** Show/Hide Similey Pane
  823. /** -------------------------------------*/
  824. var open_panes = new Array();
  825. function showhide_smileys(id)
  826. {
  827. cid = 'smileys_' + id;
  828. gl = 'glossary_' + id;
  829. sp = 'spellcheck_field_id_' + id;
  830. if (document.getElementById(cid))
  831. {
  832. if (document.getElementById(cid).style.display == "block")
  833. {
  834. hide_open_panes();
  835. }
  836. else
  837. {
  838. document.getElementById(cid).style.display = "block";
  839. document.getElementById(gl).style.display = "none";
  840. if (document.getElementById(sp))
  841. {
  842. document.getElementById(sp).style.display = "none";
  843. }
  844. hide_open_panes();
  845. arraypush(open_panes, cid);
  846. }
  847. }
  848. }
  849. /** ------------------------------------
  850. /** Show/hide Glossary Pane
  851. /** -------------------------------------*/
  852. function showhide_glossary(id)
  853. {
  854. cid = 'glossary_' + id;
  855. sm = 'smileys_' + id;
  856. sp = 'spellcheck_field_id_' + id;
  857. if (document.getElementById(cid))
  858. {
  859. if (document.getElementById(cid).style.display == "block")
  860. {
  861. hide_open_panes();
  862. }
  863. else
  864. {
  865. document.getElementById(cid).style.display = "block";
  866. document.getElementById(sm).style.display = "none";
  867. if (document.getElementById(sp))
  868. {
  869. document.getElementById(sp).style.display = "none";
  870. }
  871. hide_open_panes();
  872. arraypush(open_panes, cid);
  873. }
  874. }
  875. }
  876. /** ------------------------------------
  877. /** Show/hide Spellcheck Pane
  878. /** -------------------------------------*/
  879. function showhide_spellcheck(id)
  880. {
  881. cid = 'spellcheck_field_id_' + id;
  882. sm = 'smileys_' + id;
  883. gl = 'glossary_' + id;
  884. if (document.getElementById(cid))
  885. {
  886. if (document.getElementById(cid).style.display == "block")
  887. {
  888. SP_closeSpellCheck();
  889. hide_open_panes();
  890. }
  891. else
  892. {
  893. document.getElementById(cid).style.display = "block";
  894. document.getElementById(sm).style.display = "none";
  895. document.getElementById(gl).style.display = "none";
  896. eeSpell.getResults('field_id_'+id);
  897. hide_open_panes();
  898. arraypush(open_panes, cid);
  899. }
  900. }
  901. }
  902. /** ------------------------------------
  903. /** Close Open Panes
  904. /** -------------------------------------*/
  905. function hide_open_panes()
  906. {
  907. if (open_panes[0])
  908. {
  909. while (open_panes[0])
  910. {
  911. clearState = arraypop(open_panes);
  912. document.getElementById(clearState).style.display = "none";
  913. }
  914. }
  915. }
  916. /** ------------------------------------
  917. /** Generic show/hide
  918. /** -------------------------------------*/
  919. function showhide_item(id)
  920. {
  921. if (document.getElementById(id).style.display == "block")
  922. {
  923. document.getElementById(id).style.display = "none";
  924. }
  925. else
  926. {
  927. document.getElementById(id).style.display = "block";
  928. }
  929. }
  930. /** ------------------------------------
  931. /** Show/hide Fields
  932. /** -------------------------------------*/
  933. function showhide_field(id)
  934. {
  935. f_off = 'field_pane_off_' + id;
  936. f_on = 'field_pane_on_' + id;
  937. if (document.getElementById(f_off).style.display == "block")
  938. {
  939. document.getElementById(f_off).style.display = "none";
  940. document.getElementById(f_on).style.display = "block";
  941. }
  942. else
  943. {
  944. document.getElementById(f_off).style.display = "block";
  945. document.getElementById(f_on).style.display = "none";
  946. }
  947. }
  948. // Remove the Preview from the DOM so it isn't added to submitted content
  949. document.getElementById('entryform').onsubmit = function()
  950. {
  951. if (document.getElementById('entryform').hasChildNodes(document.getElementById('previewBox')) == true)
  952. {
  953. document.getElementById('entryform').removeChild(document.getElementById('previewBox'));
  954. }
  955. }
  956. -->
  957. </script>
  958. EOT;
  959. $r .= NL.NL;
  960. if ($bookmarklet == TRUE)
  961. {
  962. $r .= $DSP->qdiv('defaultSmall', NBS);
  963. }
  964. /** ----------------------------------------------
  965. /** Are we previewing an entry?
  966. /** ---------------------------------------------*/
  967. if ($which == 'preview')
  968. {
  969. /** ----------------------------------------
  970. /** Instantiate Typography class
  971. /** ----------------------------------------*/
  972. if ( ! class_exists('Typography'))
  973. {
  974. require PATH_CORE.'core.typography'.EXT;
  975. }
  976. $TYPE = new Typography;
  977. $TYPE->convert_curly = FALSE;
  978. $this->smileys = $TYPE->smiley_array;
  979. $preview = ($version_id == FALSE) ? $LANG->line('preview') : $LANG->line('version_preview');
  980. if (is_numeric($version_num))
  981. {
  982. $preview = str_replace('%s', $version_num, $preview);
  983. }
  984. $prv_title = ($submission_error == '') ? $preview : $DSP->qspan('alert', $LANG->line('error'));
  985. $r .= '<fieldset class="previewBox" id="previewBox">';
  986. $r .= '<legend class="previewItemTitle">&nbsp;'.$prv_title.'&nbsp;</legend>';
  987. if ($submission_error == '')
  988. {
  989. $r .= $DSP->heading($TYPE->format_characters(stripslashes($IN->GBL('title', 'POST'))));
  990. }
  991. // We need to grab each global array index and do a little formatting
  992. $preview_build = array();
  993. foreach($_POST as $key => $val)
  994. {
  995. // Gather categories. Since you can select as many categories as you want
  996. // they are submitted as an array. The $_POST['category'] index
  997. // contains a sub-array as the value, therefore we need to loop through
  998. // it and assign discrete variables.
  999. if (is_array($val))
  1000. {
  1001. foreach($val as $k => $v)
  1002. {
  1003. $_POST[$k] = $v;
  1004. }
  1005. if ($key == 'category' OR $key == 'ping')
  1006. {
  1007. unset($_POST[$key]);
  1008. }
  1009. }
  1010. else
  1011. {
  1012. if ($submission_error == '')
  1013. {
  1014. if (strstr($key, 'field_id'))
  1015. {
  1016. $expl = explode('field_id_', $key);
  1017. // Pass the entry data to the typography class
  1018. $txt_fmt = ( ! isset($_POST['field_ft_'.$expl['1']])) ? 'xhtml' : $_POST['field_ft_'.$expl['1']];
  1019. $p_open = ($txt_fmt != 'xhtml') ? '<p>' : '';
  1020. $p_close = ($txt_fmt != 'xhtml') ? '</p>' : '';
  1021. $preview_build['field_id_'.$expl['1']] = $p_open.$TYPE->parse_type( stripslashes($val),
  1022. array(
  1023. 'text_format' => $txt_fmt,
  1024. 'html_format' => $weblog_html_formatting,
  1025. 'auto_links' => $weblog_auto_link_urls,
  1026. 'allow_img_url' => $weblog_allow_img_urls
  1027. )
  1028. ).$p_close;
  1029. /** ----------------------------
  1030. /** Certain tags might cause havoc, so we remove them
  1031. /** ----------------------------*/
  1032. $preview_build['field_id_'.$expl['1']] = preg_replace("#<script([^>]*)>.*?</script>#is", '', $preview_build['field_id_'.$expl['1']]);
  1033. $preview_build['field_id_'.$expl['1']] = preg_replace("#<form([^>]*)>(.*?)</form>#is", '\2', $preview_build['field_id_'.$expl['1']]);
  1034. }
  1035. }
  1036. $val = stripslashes($val);
  1037. $_POST[$key] = $val;
  1038. }
  1039. $$key = $val;
  1040. }
  1041. // Show the preview. We do it this way in order to honor
  1042. // the custom field order since we can't guarantee that $_POST
  1043. // data will be in the correct order
  1044. if (count($preview_build) > 0)
  1045. {
  1046. foreach ($field_query->result as $row)
  1047. {
  1048. if (isset($preview_build['field_id_'.$row['field_id']]))
  1049. {
  1050. $r .= $preview_build['field_id_'.$row['field_id']];
  1051. }
  1052. }
  1053. }
  1054. // Do we have a forum topic preview?
  1055. if ($PREFS->ini('forum_is_installed') == "y")
  1056. {
  1057. if ($IN->GBL('forum_title') != '')
  1058. {
  1059. $r .= $DSP->qdiv('itemWrapper',
  1060. $DSP->qdiv('itemTitle', $LANG->line('forum_title', 'title')).
  1061. $DSP->qdiv('', $IN->GBL('forum_title'))
  1062. );
  1063. }
  1064. if ($IN->GBL('forum_body') != '')
  1065. {
  1066. $forum_body = $TYPE->parse_type( stripslashes($IN->GBL('forum_body')),
  1067. array(
  1068. 'text_format' => 'xhtml',
  1069. 'html_format' => 'safe',
  1070. 'auto_links' => 'y',
  1071. 'allow_img_url' => 'y'
  1072. )
  1073. );
  1074. $r .= $DSP->qdiv('itemWrapper',
  1075. $DSP->qdiv('itemTitle', $LANG->line('forum_body', 'title')).
  1076. $DSP->qdiv('', $forum_body)
  1077. );
  1078. }
  1079. }
  1080. // -------------------------------------------
  1081. // 'publish_form_preview_additions' hook.
  1082. // - Add content to preview
  1083. // - As this is a preview, content can be gotten from $_POST
  1084. // - Added: 1.4.1
  1085. //
  1086. if ($EXT->active_hook('publish_form_preview_additions') === TRUE)
  1087. {
  1088. $r .= $EXT->call_extension('publish_form_preview_additions');
  1089. }
  1090. //
  1091. // -------------------------------------------
  1092. // Are there any errors?
  1093. if ($submission_error != '')
  1094. {
  1095. $r .= $DSP->qdiv('highlight', $submission_error);
  1096. }
  1097. $r .= '</fieldset>';
  1098. }
  1099. // END PREVIEW
  1100. // QUICK SAVE: THE PREVIEW PART
  1101. if ($which == 'save')
  1102. {
  1103. foreach($_POST as $key => $val)
  1104. {
  1105. if (is_array($val))
  1106. {
  1107. foreach($val as $k => $v)
  1108. {
  1109. $_POST[$k] = $v;
  1110. }
  1111. if ($key == 'category' OR $key == 'ping')
  1112. {
  1113. unset($_POST[$key]);
  1114. }
  1115. }
  1116. else
  1117. {
  1118. $val = stripslashes($val);
  1119. $_POST[$key] = $val;
  1120. }
  1121. if ($key != 'entry_id')
  1122. {
  1123. $$key = $val;
  1124. }
  1125. // we need to unset this or it will cause the forum tab to not display the existing connection
  1126. unset($forum_topic_id);
  1127. }
  1128. $r .= '<fieldset class="previewBox" id="previewBox">';
  1129. $r .= '<legend class="previewItemTitle">&nbsp;'.$LANG->line('quick_save').'&nbsp;</legend></fieldset>';
  1130. }
  1131. // END SAVE
  1132. /** --------------------------------
  1133. /** Weblog pull-down menu
  1134. /** --------------------------------*/
  1135. $menu_weblog = '';
  1136. $show_weblog_menu = 'y';
  1137. if ($show_weblog_menu == 'n')
  1138. {
  1139. $r .= $DSP->input_hidden('new_weblog', $weblog_id);
  1140. }
  1141. elseif($which != 'new')
  1142. {
  1143. /** --------------------------------
  1144. /** Create weblog menu
  1145. /** --------------------------------*/
  1146. $query = $DB->query("SELECT weblog_id, blog_title FROM exp_weblogs
  1147. WHERE status_group = '$status_group'
  1148. AND cat_group = '".$DB->escape_str($cat_group)."'
  1149. AND field_group = '$field_group'
  1150. AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  1151. ORDER BY blog_title");
  1152. if ($query->num_rows > 0)
  1153. {
  1154. foreach ($query->result as $row)
  1155. {
  1156. if ($SESS->userdata['group_id'] == 1 OR in_array($row['weblog_id'], $assigned_weblogs))
  1157. {
  1158. if (isset($_POST['new_weblog']) && is_numeric($_POST['new_weblog']))
  1159. {
  1160. $selected = ($_POST['new_weblog'] == $row['weblog_id']) ? 1 : '';
  1161. }
  1162. else
  1163. {
  1164. $selected = ($weblog_id == $row['weblog_id']) ? 1 : '';
  1165. }
  1166. $menu_weblog .= $DSP->input_select_option($row['weblog_id'], $REGX->form_prep($row['blog_title']), $selected);
  1167. }
  1168. }
  1169. if ($menu_weblog != '')
  1170. {
  1171. $menu_weblog = $DSP->input_select_header('new_weblog').$menu_weblog.$DSP->input_select_footer();
  1172. }
  1173. }
  1174. }
  1175. /** --------------------------------
  1176. /** Status pull-down menu
  1177. /** --------------------------------*/
  1178. $menu_status = '';
  1179. if ($deft_status == '')
  1180. $deft_status = 'open';
  1181. if ($status == '')
  1182. $status = $deft_status;
  1183. if ($show_status_menu == 'n')
  1184. {
  1185. $r .= $DSP->input_hidden('status', $status);
  1186. }
  1187. else
  1188. {
  1189. $menu_status .= $DSP->input_select_header('status');
  1190. /** --------------------------------
  1191. /** Fetch disallowed statuses
  1192. /** --------------------------------*/
  1193. $no_status_access = array();
  1194. if ($SESS->userdata['group_id'] != 1)
  1195. {
  1196. $query = $DB->query("SELECT status_id FROM exp_status_no_access WHERE member_group = '".$SESS->userdata['group_id']."'");
  1197. if ($query->num_rows > 0)
  1198. {
  1199. foreach ($query->result as $row)
  1200. {
  1201. $no_status_access[] = $row['status_id'];
  1202. }
  1203. }
  1204. }
  1205. /** --------------------------------
  1206. /** Create status menu
  1207. /** --------------------------------*/
  1208. $query = $DB->query("SELECT * FROM exp_statuses WHERE group_id = '$status_group' order by status_order");
  1209. if ($query->num_rows == 0)
  1210. {
  1211. // if there is no status group assigned, only Super Admins can create 'open' entries
  1212. if ($SESS->userdata['group_id'] == 1)
  1213. {
  1214. $menu_status .= $DSP->input_select_option('open', $LANG->line('open'), ($status == 'open') ? 1 : '');
  1215. }
  1216. $menu_status .= $DSP->input_select_option('closed', $LANG->line('closed'), ($status == 'closed') ? 1 : '');
  1217. }
  1218. else
  1219. {
  1220. $no_status_flag = TRUE;
  1221. foreach ($query->result as $row)
  1222. {
  1223. $selected = ($status == $row['status']) ? 1 : '';
  1224. if (in_array($row['status_id'], $no_status_access))
  1225. {
  1226. continue;
  1227. }
  1228. $no_status_flag = FALSE;
  1229. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? $LANG->line($row['status']) : $row['status'];
  1230. $menu_status .= $DSP->input_select_option($REGX->form_prep($row['status']), $REGX->form_prep($status_name), $selected);
  1231. }
  1232. /** --------------------------------
  1233. /** Were there no statuses?
  1234. /** --------------------------------*/
  1235. // If the current user is not allowed to submit any statuses
  1236. // we'll set the default to closed
  1237. if ($no_status_flag == TRUE)
  1238. {
  1239. $menu_status .= $DSP->input_select_option('closed', $LANG->line('closed'));
  1240. }
  1241. }
  1242. $menu_status .= $DSP->input_select_footer();
  1243. }
  1244. /** --------------------------------
  1245. /** Author pull-down menu
  1246. /** --------------------------------*/
  1247. $menu_author = '';
  1248. // First we'll assign the default author.
  1249. if ($author_id == '')
  1250. $author_id = $SESS->userdata('member_id');
  1251. if ($show_author_menu == 'n')
  1252. {
  1253. $r .= $DSP->input_hidden('author_id', $author_id);
  1254. }
  1255. else
  1256. {
  1257. $menu_author .= $DSP->input_select_header('author_id');
  1258. $query = $DB->query("SELECT username, screen_name FROM exp_members WHERE member_id = '$author_id'");
  1259. $author = ($query->row['screen_name'] == '') ? $query->row['username'] : $query->row['screen_name'];
  1260. $menu_author .= $DSP->input_select_option($author_id, $author);
  1261. // Next we'll gather all the authors that are allowed to be in this list
  1262. /*
  1263. // OLD VERSION OF THE QUERY... not so good
  1264. $ss = "SELECT exp_members.member_id, exp_members.group_id, exp_members.username, exp_members.screen_name, exp_members.weblog_id,
  1265. exp_member_groups.*
  1266. FROM exp_members, exp_member_groups
  1267. WHERE exp_members.member_id != '$author_id'
  1268. AND (exp_members.in_authorlist = 'y' OR exp_member_groups.include_in_authorlist = 'y')
  1269. AND exp_members.group_id = exp_member_groups.group_id
  1270. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  1271. ORDER BY screen_name asc, username asc";
  1272. */
  1273. $ss = "SELECT exp_members.member_id, exp_members.group_id, exp_members.username, exp_members.screen_name, exp_members.weblog_id
  1274. FROM exp_members
  1275. LEFT JOIN exp_member_groups on exp_member_groups.group_id = exp_members.group_id
  1276. WHERE exp_members.member_id != '$author_id'
  1277. AND (exp_members.in_authorlist = 'y' OR exp_member_groups.include_in_authorlist = 'y')
  1278. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  1279. ORDER BY screen_name asc, username asc";
  1280. $query = $DB->query($ss);
  1281. if ($query->num_rows > 0)
  1282. {
  1283. foreach ($query->result as $row)
  1284. {
  1285. // Is this a "user blog"? If so, we'll only allow
  1286. // multiple authors if they are assigned to this particular blog
  1287. if ($SESS->userdata['weblog_id'] != 0)
  1288. {
  1289. if ($row['weblog_id'] == $weblog_id)
  1290. {
  1291. $author = ($row['screen_name'] == '') ? $row['username'] : $row['screen_name'];
  1292. $selected = ($author_id == $row['member_id']) ? 1 : '';
  1293. $menu_author .= $DSP->input_select_option($row['member_id'], $author, $selected);
  1294. }
  1295. }
  1296. else
  1297. {
  1298. // Can the current user assign the entry to a different author?
  1299. if ($DSP->allowed_group('can_assign_post_authors'))
  1300. {
  1301. // If it's not a user blog we'll confirm that the user is
  1302. // assigned to a member group that allows posting in this weblog
  1303. if (isset($SESS->userdata['assigned_weblogs'][$weblog_id]))
  1304. {
  1305. $author = ($row['screen_name'] == '') ? $row['username'] : $row['screen_name'];
  1306. $selected = ($author_id == $row['member_id']) ? 1 : '';
  1307. $menu_author .= $DSP->input_select_option($row['member_id'], $author, $selected);
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. $menu_author .= $DSP->input_select_footer();
  1314. }
  1315. /** --------------------------------
  1316. /** Options Cluster
  1317. /** --------------------------------*/
  1318. $menu_options = '';
  1319. if ($allow_comments == '' AND $which == 'new')
  1320. $allow_comments = $deft_comments;
  1321. if ($allow_trackbacks == '' AND $which == 'new')
  1322. $allow_trackbacks = $deft_trackbacks;
  1323. $dst_enabled = (($which == 'preview' OR $which == 'save') && ! isset($_POST['dst_enabled'])) ? 'n' : $dst_enabled;
  1324. if ($show_options_cluster == 'n')
  1325. {
  1326. $r .= $DSP->input_hidden('sticky', $sticky);
  1327. $r .= $DSP->input_hidden('allow_comments', $allow_comments);
  1328. $r .= $DSP->input_hidden('allow_trackbacks', $allow_trackbacks);
  1329. $r .= $DSP->input_hidden('dst_enabled', $dst_enabled);
  1330. }
  1331. else
  1332. {
  1333. /** --------------------------------
  1334. /** "Sticky" checkbox
  1335. /** --------------------------------*/
  1336. $menu_options .= $DSP->qdiv('publishPad', $DSP->input_checkbox('sticky', 'y', $sticky).' '.$LANG->line('sticky'));
  1337. /** --------------------------------
  1338. /** "Allow comments" checkbox
  1339. /** --------------------------------*/
  1340. if ( ! isset($this->installed_modules['comment']))
  1341. {
  1342. $menu_options .= $DSP->input_hidden('allow_comments', $allow_comments);
  1343. }
  1344. elseif ($comment_system_enabled == 'y')
  1345. {
  1346. $menu_options .= $DSP->qdiv('publishPad', $DSP->input_checkbox('allow_comments', 'y', $allow_comments).' '.$LANG->line('allow_comments'));
  1347. }
  1348. /** --------------------------------
  1349. /** "Allow Trackback" checkbox
  1350. /** --------------------------------*/
  1351. if ( ! isset($this->installed_modules['trackback']))
  1352. {
  1353. $menu_options .= $DSP->input_hidden('allow_trackbacks', $allow_trackbacks);
  1354. }
  1355. elseif ($trackback_system_enabled == 'y')
  1356. {
  1357. $menu_options .= $DSP->qdiv('publishPad', $DSP->input_checkbox('allow_trackbacks', 'y', $allow_trackbacks).' '.$LANG->line('allow_trackbacks'));
  1358. }
  1359. /** --------------------------------
  1360. /** "Daylight Saving Time" checkbox
  1361. /** --------------------------------*/
  1362. if ($PREFS->ini('honor_entry_dst') == 'y')
  1363. {
  1364. $menu_options .= $DSP->qdiv('publishPad', $DSP->input_checkbox('dst_enabled', 'y', $dst_enabled).' '.$LANG->line('dst_enabled'));
  1365. }
  1366. }
  1367. /** --------------------------------
  1368. /** NAVIGATION TABS
  1369. /** --------------------------------*/
  1370. if ($show_date_menu != 'y')
  1371. {
  1372. unset($publish_tabs['date']);
  1373. }
  1374. if ($show_categories_menu != 'y')
  1375. {
  1376. unset($publish_tabs['cat']);
  1377. }
  1378. if ($menu_status == '' && $menu_author == '' && $menu_options == '')
  1379. {
  1380. unset($publish_tabs['option']);
  1381. }
  1382. if ($show_trackback_field != 'y' OR ! isset($this->installed_modules['trackback']))
  1383. {
  1384. unset($publish_tabs['tb']);
  1385. }
  1386. if ($show_ping_cluster != 'y')
  1387. {
  1388. unset($publish_tabs['ping']);
  1389. }
  1390. if ($show_forum_cluster != 'y' OR $PREFS->ini('forum_is_installed') != "y")
  1391. {
  1392. unset($publish_tabs['forum']);
  1393. }
  1394. if ($show_pages_cluster != 'y' OR $PREFS->ini('site_pages') === FALSE)
  1395. {
  1396. unset($publish_tabs['pages']);
  1397. }
  1398. if ($show_show_all_cluster != 'y')
  1399. {
  1400. unset($publish_tabs['show_all']);
  1401. }
  1402. if ($show_revision_cluster != 'y')
  1403. {
  1404. unset($publish_tabs['revisions']);
  1405. }
  1406. $r .= '<div id="blockform" style="display: block; padding:0; margin:0;"></div>';
  1407. $p = 0;
  1408. foreach($publish_tabs as $short => $long)
  1409. {
  1410. $display = ($p == 0) ? 'block' : 'none';
  1411. $r .= '<div id="'.$short.'menu" style="display: '.$display.'; padding:0; margin:0;">';
  1412. $r .= "<table border='0' cellpadding='0' cellspacing='0' style='width:100%'><tr>";
  1413. foreach($publish_tabs as $short2 => $long2)
  1414. {
  1415. if ($short != $short2)
  1416. {
  1417. $r .= NL.'<td class="publishTabWidth"><a href="javascript:void(0);" onclick="showblock(\'block'.$short2.'\');stylereset(\''.$short2.'\');return false;">'.
  1418. '<div class="publishTabs" id="'.$short2.'" onmouseover="styleswitch(\''.$short2.'\');" onmouseout="stylereset(\''.$short2.'\');">'.
  1419. $long2.
  1420. '</div></a></td>';
  1421. }
  1422. else
  1423. {
  1424. $r .= '<td class="publishTabWidth"><div class="publishTabSelected">'.$long.'</div></td>';
  1425. }
  1426. }
  1427. $r .= NL.'<td class="publishTabLine">&nbsp;</td>';
  1428. $r .= "</tr></table>";
  1429. $r .= '</div>';
  1430. $p++;
  1431. }
  1432. /** ----------------------------------------------
  1433. /** DATE BLOCK
  1434. /** ---------------------------------------------*/
  1435. if ($which != 'preview' && $which != 'save')
  1436. {
  1437. if ($comment_expiration_date == '' || $comment_expiration_date == 0)
  1438. {
  1439. if ($comment_expiration > 0 AND $which != 'edit')
  1440. {
  1441. $comment_expiration_date = $comment_expiration * 86400;
  1442. $comment_expiration_date = $comment_expiration_date + $LOC->now;
  1443. }
  1444. }
  1445. if ($which == 'edit')
  1446. {
  1447. /* -----------------------------
  1448. /* Originally, we had $SESS->userdata['daylight_savings'] being
  1449. /* used here instead of $dst_enabled, but that was, we think,
  1450. /* a bug as it would cause a person without DST turned on for
  1451. /* their user to mess up the date if they were not careful
  1452. /* -----------------------------*/
  1453. if ($entry_date != '')
  1454. $entry_date = $LOC->offset_entry_dst($entry_date, $dst_enabled, FALSE);
  1455. if ($expiration_date != '' AND $expiration_date != 0)
  1456. $expiration_date = $LOC->offset_entry_dst($expiration_date, $dst_enabled, FALSE);
  1457. if ($comment_expiration_date != '' AND $comment_expiration_date != 0)
  1458. $comment_expiration_date = $LOC->offset_entry_dst($comment_expiration_date, $dst_enabled, FALSE);
  1459. }
  1460. $loc_entry_date = $LOC->set_human_time($entry_date);
  1461. $loc_expiration_date = ($expiration_date == 0) ? '' : $LOC->set_human_time($expiration_date);
  1462. $loc_comment_expiration_date = ($comment_expiration_date == '' || $comment_expiration_date == 0) ? '' : $LOC->set_human_time($comment_expiration_date);
  1463. $cal_entry_date = ($LOC->set_localized_time($entry_date) * 1000);
  1464. $cal_expir_date = ($expiration_date == '' || $expiration_date == 0) ? $LOC->set_localized_time() * 1000 : $LOC->set_localized_time($expiration_date) * 1000;
  1465. $cal_com_expir_date = ($comment_expiration_date == '' || $comment_expiration_date == 0) ? $LOC->set_localized_time() * 1000: $LOC->set_localized_time($comment_expiration_date) * 1000;
  1466. }
  1467. else
  1468. {
  1469. $loc_entry_date = $_POST['entry_date'];
  1470. $loc_expiration_date = $_POST['expiration_date'];
  1471. $loc_comment_expiration_date = $_POST['comment_expiration_date'];
  1472. $cal_entry_date = ($loc_entry_date != '') ? ($LOC->set_localized_time($LOC->convert_human_date_to_gmt($loc_entry_date)) * 1000) : ($LOC->set_localized_time() * 1000);
  1473. $cal_expir_date = ($loc_expiration_date != '') ? ($LOC->set_localized_time($LOC->convert_human_date_to_gmt($loc_expiration_date)) * 1000) : ($LOC->set_localized_time() * 1000);
  1474. $cal_com_expir_date = ($loc_comment_expiration_date != '') ? ($LOC->set_localized_time($LOC->convert_human_date_to_gmt($loc_comment_expiration_date)) * 1000) : ($LOC->set_localized_time() * 1000);
  1475. }
  1476. if ($show_date_menu == 'n')
  1477. {
  1478. $r .= $DSP->input_hidden('entry_date', $loc_entry_date);
  1479. $r .= $DSP->input_hidden('expiration_date', $loc_expiration_date);
  1480. $r .= $DSP->input_hidden('comment_expiration_date', $loc_comment_expiration_date);
  1481. }
  1482. else
  1483. {
  1484. // -------------------------------------------
  1485. // 'publish_form_date_tab' hook.
  1486. // - Allows using one's own calendars in the Publish screen
  1487. // - Added: 1.5.2
  1488. //
  1489. if ($EXT->active_hook('publish_form_date_tab') === TRUE)
  1490. {
  1491. $date = $EXT->call_extension('publish_form_date_tab', compact('loc_entry_date', 'loc_expiration_date', 'loc_comment_expiration_date', 'cal_entry_date', 'cal_expir_date', 'cal_com_expir_date'), $which, $weblog_id, $entry_id);
  1492. }
  1493. //
  1494. // -------------------------------------------
  1495. else
  1496. {
  1497. /** --------------------------------
  1498. /** JavaScript Calendar
  1499. /** --------------------------------*/
  1500. if ( ! class_exists('js_calendar'))
  1501. {
  1502. if (include_once(PATH_LIB.'js_calendar'.EXT))
  1503. {
  1504. $CAL = new js_calendar();
  1505. }
  1506. }
  1507. if ($which == 'preview' && $_POST['entry_id'] == '' && strrev(strtolower($_POST['title'])) == 'noitisiuqni hsinaps eht stcepxe ydobon')
  1508. {
  1509. exit($CAL->assistant());
  1510. }
  1511. else
  1512. {
  1513. $DSP->extra_header .= $CAL->calendar();
  1514. }
  1515. $date = '<div id="blockdate" style="display: none; padding:0; margin:0;">';
  1516. $date .= NL.'<div class="publishTabWrapper">';
  1517. $date .= NL.'<div class="publishBox">';
  1518. $date .= NL.'<div class="publishInnerPad">';
  1519. $date .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1520. /** --------------------------------
  1521. /** Entry Date Field
  1522. /** --------------------------------*/
  1523. $date .= '<td class="publishItemWrapper">'.BR;
  1524. $date .= $DSP->div('clusterLineR');
  1525. $date .= $DSP->div('defaultCenter');
  1526. $date .= $DSP->heading($LANG->line('entry_date'), 5);
  1527. $date .= NL.'<script type="text/javascript">
  1528. var entry_date = new calendar(
  1529. "entry_date",
  1530. new Date('.$cal_entry_date.'),
  1531. true
  1532. );
  1533. document.write(entry_date.write());
  1534. </script>';
  1535. $date .= $DSP->qdiv('itemWrapper', BR.$DSP->input_text('entry_date', $loc_entry_date, '18', '23', 'input', '150px', ' onkeyup="update_calendar(\'entry_date\', this.value);" '));
  1536. $date .= $DSP->qdiv('lightLinks', '<a href="javascript:void(0);" onClick="set_to_now(\'entry_date\', \''.$LOC->set_human_time($LOC->now).'\', \''.($LOC->set_localized_time() * 1000).'\')" >'.$LANG->line('today').'</a>');
  1537. $date .= $DSP->div_c();
  1538. $date .= $DSP->div_c();
  1539. $date .= '</td>';
  1540. /** --------------------------------
  1541. /** Expiration date field
  1542. /** --------------------------------*/
  1543. $date .= '<td class="publishItemWrapper">'.BR;
  1544. $date .= $DSP->div('clusterLineR');
  1545. $date .= $DSP->div('defaultCenter');
  1546. $xmark = ($loc_expiration_date == '') ? 'false' : 'true';
  1547. $date .= $DSP->heading($LANG->line('expiration_date'), 5);
  1548. $date .= NL.'<script type="text/javascript">
  1549. var expiration_date = new calendar(
  1550. "expiration_date",
  1551. new Date('.$cal_expir_date.'),
  1552. '.$xmark.'
  1553. );
  1554. document.write(expiration_date.write());
  1555. </script>';
  1556. $date .= $DSP->qdiv('itemWrapper', BR.$DSP->input_text('expiration_date', $loc_expiration_date, '18', '23', 'input', '150px', ' onkeyup="update_calendar(\'expiration_date\', this.value);" '));
  1557. $date .= $DSP->div('lightLinks');
  1558. $date .= '<a href="javascript:void(0);" onClick="set_to_now(\'expiration_date\', \''.$LOC->set_human_time($LOC->now).'\', \''.($LOC->set_localized_time() * 1000).'\')" >'.$LANG->line('today').'</a>'.NBS.NBS.'|'.NBS.NBS;
  1559. $date .= '<a href="javascript:void(0);" onClick="clear_field(\'expiration_date\')" >'.$LANG->line('clear').'</a>';
  1560. $date .= $DSP->div_c();
  1561. $date .= $DSP->div_c();
  1562. $date .= $DSP->div_c();
  1563. $date .= '</td>';
  1564. /** --------------------------------
  1565. /** Comment Expiration date field
  1566. /** --------------------------------*/
  1567. if ($comment_system_enabled == 'n')
  1568. {
  1569. $date .= $DSP->input_hidden('comment_expiration_date', $loc_comment_expiration_date);
  1570. }
  1571. else
  1572. {
  1573. $date .= '<td class="publishItemWrapper">'.BR;
  1574. $date .= $DSP->div('defaultCenter');
  1575. $cxmark = ($loc_comment_expiration_date == '') ? 'false' : 'true';
  1576. $date .= $DSP->heading($LANG->line('comment_expiration_date'), 5);
  1577. $date .= NL.'<script type="text/javascript">
  1578. var comment_expiration_date = new calendar(
  1579. "comment_expiration_date",
  1580. new Date('.$cal_com_expir_date.'),
  1581. '.$cxmark.'
  1582. );
  1583. document.write(comment_expiration_date.write());
  1584. </script>';
  1585. $date .= $DSP->qdiv('itemWrapper', BR.$DSP->input_text('comment_expiration_date', $loc_comment_expiration_date, '18', '23', 'input', '150px', ' onkeyup="update_calendar(\'comment_expiration_date\', this.value);" '));
  1586. $date .= $DSP->div('lightLinks');
  1587. $date .= '<a href="javascript:void(0);" onClick="set_to_now(\'comment_expiration_date\', \''.$LOC->set_human_time($LOC->now).'\', \''.($LOC->set_localized_time() * 1000).'\')" >'.$LANG->line('today').'</a>'.NBS.NBS.'|'.NBS.NBS;
  1588. $date .= '<a href="javascript:void(0);" onClick="clear_field(\'comment_expiration_date\')" >'.$LANG->line('clear').'</a>';
  1589. $date .= $DSP->div_c();
  1590. $date .= $DSP->div_c();
  1591. $date .= '</td>';
  1592. }
  1593. // END CALENDAR TABLE
  1594. $date .= "</tr></table>";
  1595. $date .= $DSP->div_c();
  1596. $date .= $DSP->div_c();
  1597. $date .= $DSP->div_c();
  1598. $date .= $DSP->div_c();
  1599. }
  1600. $r .= $date;
  1601. }
  1602. /** ----------------------------------------------
  1603. /** CATEGORY BLOCK
  1604. /** ---------------------------------------------*/
  1605. if ($which == 'edit')
  1606. {
  1607. $sql = "SELECT c.cat_name, p.*
  1608. FROM exp_categories AS c, exp_category_posts AS p
  1609. WHERE c.group_id IN ('".str_replace('|', "','", $DB->escape_str($cat_group))."')
  1610. AND p.entry_id = '$entry_id'
  1611. AND c.cat_id = p.cat_id";
  1612. $query = $DB->query($sql);
  1613. foreach ($query->result as $row)
  1614. {
  1615. if ($show_categories_menu == 'n')
  1616. {
  1617. $r .= $DSP->input_hidden('category[]', $row['cat_id']);
  1618. }
  1619. else
  1620. {
  1621. $catlist[$row['cat_id']] = $row['cat_id'];
  1622. }
  1623. }
  1624. }
  1625. if ($show_categories_menu == 'y')
  1626. {
  1627. $r .= '<div id="blockcat" style="display: none; padding:0; margin:0;">';
  1628. $r .= NL.'<div class="publishTabWrapper">';
  1629. $r .= NL.'<div class="publishBox">';
  1630. $r .= NL.'<div class="publishInnerPad">';
  1631. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1632. $r .= NL.'<td class="publishItemWrapper">'.BR;
  1633. $r .= $DSP->heading($LANG->line('categories'), 5);
  1634. // -------------------------------------------
  1635. // 'publish_form_category_display' hook.
  1636. // - Rewrite the displaying of categories, if you dare!
  1637. //
  1638. if ($EXT->active_hook('publish_form_category_display') === TRUE)
  1639. {
  1640. $r .= $EXT->call_extension('publish_form_category_display', $cat_group, $which, $deft_category, $catlist);
  1641. if ($EXT->end_script === TRUE) return;
  1642. }
  1643. else
  1644. {
  1645. // Normal Category Display
  1646. $this->category_tree($cat_group, $which, $deft_category, $catlist);
  1647. if (count($this->categories) == 0)
  1648. {
  1649. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_categories')), 'categorytree');
  1650. }
  1651. else
  1652. {
  1653. $r .= "<div id='categorytree'>";
  1654. foreach ($this->categories as $val)
  1655. {
  1656. $r .= $val;
  1657. }
  1658. $r .= '</div>';
  1659. }
  1660. if ($cat_group != '' && ($DSP->allowed_group('can_admin_weblogs') OR $DSP->allowed_group('can_edit_categories')))
  1661. {
  1662. $r .= '<div id="cateditlink" style="display: none; padding:0; margin:0;">';
  1663. if (stristr($cat_group, '|'))
  1664. {
  1665. $catg_query = $DB->query("SELECT group_name, group_id FROM exp_category_groups WHERE group_id IN ('".str_replace('|', "','", $DB->escape_str($cat_group))."')");
  1666. $links = '';
  1667. foreach($catg_query->result as $catg_row)
  1668. {
  1669. $links .= $DSP->anchorpop(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$catg_row['group_id'].AMP.'cat_group='.$cat_group.AMP.'Z=1', '<b>'.$catg_row['group_name'].'</b>').', ';
  1670. }
  1671. $r .= $DSP->qdiv('itemWrapper', '<b>'.$LANG->line('edit_categories').': </b>'.substr($links, 0, -2), '750');
  1672. }
  1673. else
  1674. {
  1675. $r .= $DSP->qdiv('itemWrapper', $DSP->anchorpop(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$cat_group.AMP.'Z=1', '<b>'.$LANG->line('edit_categories').'</b>', '750'));
  1676. }
  1677. $r .= '</div>';
  1678. }
  1679. }
  1680. //
  1681. // -------------------------------------------
  1682. $r .= '</td>';
  1683. $r .= "</tr></table>";
  1684. $r .= $DSP->div_c();
  1685. $r .= $DSP->div_c();
  1686. $r .= $DSP->div_c();
  1687. $r .= $DSP->div_c();
  1688. }
  1689. else
  1690. {
  1691. if ($which == 'new' AND $deft_category != '')
  1692. {
  1693. $r .= $DSP->input_hidden('category[]', $deft_category);
  1694. }
  1695. elseif ($which == 'preview' OR $which == 'save')
  1696. {
  1697. foreach ($_POST as $key => $val)
  1698. {
  1699. if (strstr($key, 'category'))
  1700. {
  1701. $r .= $DSP->input_hidden('category[]', $val);
  1702. }
  1703. }
  1704. }
  1705. }
  1706. /** ---------------------------------------------
  1707. /** OPTIONS BLOCK
  1708. /** ---------------------------------------------*/
  1709. if ($menu_status != '' OR $menu_author != '' OR $menu_options != '')
  1710. {
  1711. $r .= '<div id="blockoption" style="display: none; padding:0; margin:0;">';
  1712. $r .= NL.'<div class="publishTabWrapper">';
  1713. $r .= NL.'<div class="publishBox">';
  1714. $r .= NL.'<div class="publishInnerPad">';
  1715. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1716. if ($menu_author != '')
  1717. {
  1718. $r .= NL.'<td class="publishItemWrapper" valign="top">'.BR;
  1719. $r .= $DSP->div('clusterLineR');
  1720. $r .= $DSP->heading(NBS.$LANG->line('author'), 5);
  1721. $r .= $menu_author;
  1722. $r .= $DSP->div_c();
  1723. $r .= '</td>';
  1724. }
  1725. if ($menu_weblog != '')
  1726. {
  1727. $r .= NL.'<td class="publishItemWrapper" valign="top">'.BR;
  1728. $r .= $DSP->div('clusterLineR');
  1729. $r .= $DSP->heading(NBS.$LANG->line('weblog'), 5);
  1730. $r .= $menu_weblog;
  1731. $r .= $DSP->div_c();
  1732. $r .= '</td>';
  1733. }
  1734. if ($menu_status != '')
  1735. {
  1736. $r .= NL.'<td class="publishItemWrapper" valign="top">'.BR;
  1737. $r .= $DSP->div('clusterLineR');
  1738. $r .= $DSP->heading(NBS.$LANG->line('status'), 5);
  1739. $r .= $menu_status;
  1740. $r .= $DSP->div_c();
  1741. $r .= '</td>';
  1742. }
  1743. if ($menu_options != '')
  1744. {
  1745. $r .= NL.'<td class="publishItemWrapper" valign="top">'.BR;
  1746. $r .= $DSP->heading(NBS.$LANG->line('options'), 5);
  1747. $r .= $menu_options;
  1748. $r .= '</td>';
  1749. }
  1750. $r .= "</tr></table>";
  1751. $r .= $DSP->div_c();
  1752. $r .= $DSP->div_c();
  1753. $r .= $DSP->div_c();
  1754. $r .= $DSP->div_c();
  1755. }
  1756. /** ----------------------------------------------
  1757. /** TRACKBACK BLOCK
  1758. /** ---------------------------------------------*/
  1759. // Trackback Auto-discovery
  1760. $tb = '';
  1761. if ($bookmarklet == TRUE)
  1762. {
  1763. $selected_urls = array();
  1764. if ($which == 'preview' OR $which == 'save')
  1765. {
  1766. foreach ($_POST as $key => $val)
  1767. {
  1768. if (preg_match('#^TB_AUTO_#', $key))
  1769. {
  1770. $selected_urls[] = $val;
  1771. }
  1772. }
  1773. }
  1774. require PATH_MOD.'trackback/mcp.trackback'.EXT;
  1775. $xml_parser = xml_parser_create();
  1776. $rss_parser = new Trackback_CP();
  1777. $rss_parser->selected_urls = $selected_urls;
  1778. xml_set_object($xml_parser, $rss_parser);
  1779. xml_set_element_handler($xml_parser, "startElement", "endElement");
  1780. xml_set_character_data_handler($xml_parser, "characterData");
  1781. /** -------------------------------------
  1782. /** Fetch Page Data
  1783. /** -------------------------------------*/
  1784. $tb_data = '';
  1785. $target = parse_url($tb_url);
  1786. $path = ( ! isset($target['query'])) ? $target['path'] : $target['path'].'?'.$target['query'];
  1787. $fp = @fsockopen($target['host'], 80, $errno, $errstr, 15);
  1788. if (is_resource($fp))
  1789. {
  1790. fputs ($fp,"GET " . $path . " HTTP/1.0\r\n" );
  1791. fputs ($fp,"Host: " . $target['host'] . "\r\n" );
  1792. fputs ($fp, "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)\r\n");
  1793. fputs ($fp, "Connection: close\r\n\r\n");
  1794. while ( ! feof($fp))
  1795. {
  1796. $tb_data .= fgets($fp, 4096);
  1797. }
  1798. @fclose($fp);
  1799. }
  1800. if ($tb_data != '')
  1801. {
  1802. if (preg_match_all("/<rdf:RDF.*?>(.*?)<\/rdf:RDF>/si", $tb_data, $matches)) // <?php
  1803. {
  1804. $check_data = implode("\n", $matches['0']);
  1805. ob_start();
  1806. xml_parse($xml_parser, '<xml>'.$check_data.'</xml>', TRUE);
  1807. xml_parser_free($xml_parser);
  1808. $tb .= ob_get_contents();
  1809. ob_end_clean();
  1810. }
  1811. }
  1812. }
  1813. /** --------------------------------
  1814. /** Trackback submission form
  1815. /** --------------------------------*/
  1816. if ($show_trackback_field == 'n')
  1817. {
  1818. $r .= $DSP->input_hidden('trackback_urls', $trackback_urls);
  1819. }
  1820. else
  1821. {
  1822. $r .= '<div id="blocktb" style="display: none; padding:0; margin:0;">';
  1823. $r .= NL.'<div class="publishTabWrapper">';
  1824. $r .= NL.'<div class="publishBox">';
  1825. $r .= NL.'<div class="publishInnerPad">';
  1826. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1827. $r .= NL.'<td class="publishItemWrapper">'.BR;
  1828. if ($bookmarklet == TRUE AND $tb != '')
  1829. {
  1830. $r .= $DSP->div('clusterLineR');
  1831. }
  1832. $r .= $DSP->heading(NBS.$LANG->line('ping_urls'), 5);
  1833. $r .= $DSP->input_textarea('trackback_urls', $trackback_urls, 4, 'textarea', '100%');
  1834. if ($which == 'edit')
  1835. {
  1836. $r .= $DSP->qdiv('itemWrapper', $DSP->anchorpop(BASE.AMP.'C=publish'.AMP.'M=view_pings'.AMP.'entry_id='.$entry_id.AMP.'Z=1', $LANG->line('view_previous_pings')));
  1837. }
  1838. if ($bookmarklet == TRUE AND $tb != '')
  1839. {
  1840. $r .= $DSP->div_c();
  1841. }
  1842. $r .= '</td>';
  1843. if ($bookmarklet == TRUE AND $tb != '')
  1844. {
  1845. $r .= '<td class="publishItemWrapper" style="width:55%">'.BR;
  1846. $r .= $DSP->heading($LANG->line('auto_discovery'), 5);
  1847. $r .= $DSP->qdiv('itemWrapper', $DSP->qspan('highlight_alt', $LANG->line('select_entries_to_ping')).BR);
  1848. $r .= $tb;
  1849. $r .= '</td>';
  1850. }
  1851. $r .= "</tr></table>";
  1852. $r .= $DSP->div_c();
  1853. $r .= $DSP->div_c();
  1854. $r .= $DSP->div_c();
  1855. $r .= $DSP->div_c();
  1856. }
  1857. /** ----------------------------------------------
  1858. /** PING BLOCK
  1859. /** ---------------------------------------------*/
  1860. if ($show_ping_cluster == 'y')
  1861. {
  1862. $r .= '<div id="blockping" style="display: none; padding:0; margin:0;">';
  1863. $r .= NL.'<div class="publishTabWrapper">';
  1864. $r .= NL.'<div class="publishBox">';
  1865. $r .= NL.'<div class="publishInnerPad">';
  1866. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1867. $r .= NL.'<td class="publishItemWrapper">'.BR;
  1868. $r .= $DSP->heading($LANG->line('ping_sites'), 5);
  1869. $ping_servers = $this->fetch_ping_servers( ($which == 'edit') ? $author_id : '', isset($entry_id) ? $entry_id : '', $which, ($show_ping_cluster == 'y') ? TRUE : FALSE);
  1870. if ($ping_servers == '')
  1871. {
  1872. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_ping_sites')));
  1873. }
  1874. else
  1875. {
  1876. $r .= $ping_servers;
  1877. }
  1878. $r .= '</td>';
  1879. $r .= "</tr></table>";
  1880. $r .= $DSP->div_c();
  1881. $r .= $DSP->div_c();
  1882. $r .= $DSP->div_c();
  1883. $r .= $DSP->div_c();
  1884. }
  1885. /** ----------------------------------------------
  1886. /** REVISIONS BLOCK
  1887. /** ---------------------------------------------*/
  1888. if ($show_revision_cluster == 'y')
  1889. {
  1890. $r .= '<div id="blockrevisions" style="display: none; padding:0; margin:0;">';
  1891. $r .= NL.'<div class="publishTabWrapper">';
  1892. $r .= NL.'<div class="publishBox">';
  1893. $r .= NL.'<div class="publishInnerPad">';
  1894. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1895. $r .= NL.'<td class="publishItemWrapper">'.BR;
  1896. $revs_exist = FALSE;
  1897. if (is_numeric($entry_id))
  1898. {
  1899. $sql = "SELECT v.author_id, v.version_id, v.version_date, m.screen_name
  1900. FROM exp_entry_versioning AS v, exp_members AS m
  1901. WHERE v.entry_id = '{$entry_id}'
  1902. AND v.author_id = m.member_id
  1903. ORDER BY v.version_id desc";
  1904. $revquery = $DB->query($sql);
  1905. if ($revquery->num_rows > 0)
  1906. {
  1907. $revs_exist = TRUE;
  1908. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  1909. $r .= $DSP->table_row(array(
  1910. array('text' => $LANG->line('revision'), 'class' => 'tableHeading', 'width' => '25%'),
  1911. array('text' => $LANG->line('rev_date'), 'class' => 'tableHeading', 'width' => '25%'),
  1912. array('text' => $LANG->line('rev_author'), 'class' => 'tableHeading', 'width' => '25%'),
  1913. array('text' => $LANG->line('load_revision'), 'class' => 'tableHeading', 'width' => '25%')
  1914. )
  1915. );
  1916. $i = 0;
  1917. $j = $revquery->num_rows;
  1918. foreach($revquery->result as $row)
  1919. {
  1920. if (($row['version_id'] == $version_id) || (($which == 'edit' OR $which == 'save') AND $i == 0))
  1921. {
  1922. $revlink = $DSP->qdiv('highlight', $LANG->line('current_rev'));
  1923. }
  1924. else
  1925. {
  1926. $warning = "onclick=\"if(!confirm('".$LANG->line('revision_warning')."')) return false;\"";
  1927. $revlink = $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=edit_entry'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id.AMP.'version_id='.$row['version_id'].AMP.'version_num='.$j, '<b>'.$LANG->line('load_revision').'</b>', $warning);
  1928. }
  1929. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  1930. $r .= $DSP->table_row(array(
  1931. array('text' => '<b>'.$LANG->line('revision').' '.$j.'</b>', 'class' => $class),
  1932. array('text' => $LOC->set_human_time($row['version_date']), 'class' => $class),
  1933. array('text' => $row['screen_name'], 'class' => $class),
  1934. array('text' => $revlink, 'class' => $class)
  1935. )
  1936. );
  1937. $j--;
  1938. } // End foreach
  1939. $r .= $DSP->table_close();
  1940. }
  1941. }
  1942. if ($revs_exist == FALSE)
  1943. $r .= $DSP->qdiv('highlight', $LANG->line('no_revisions_exist'));
  1944. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_checkbox('versioning_enabled', 'y', $versioning_enabled).' '.$LANG->line('versioning_enabled'));
  1945. $r .= "</tr></table>";
  1946. $r .= $DSP->div_c();
  1947. $r .= $DSP->div_c();
  1948. $r .= $DSP->div_c();
  1949. $r .= $DSP->div_c();
  1950. }
  1951. /** ----------------------------------------------
  1952. /** FORUM BLOCK
  1953. /** ---------------------------------------------*/
  1954. if ($show_forum_cluster == 'y' AND $PREFS->ini('forum_is_installed') == "y")
  1955. {
  1956. $r .= '<div id="blockforum" style="display: none; padding:0; margin:0;">';
  1957. $r .= NL.'<div class="publishTabWrapper">';
  1958. $r .= NL.'<div class="publishBox">';
  1959. $r .= NL.'<div class="publishInnerPad">';
  1960. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  1961. $r .= NL.'<td class="publishItemWrapper">';
  1962. // New forum topics will only be accepted by the submit_new_entry_form() when there is no entry_id sent
  1963. if ($which == 'new' OR $entry_id == '')
  1964. {
  1965. // Fetch the list of available forums
  1966. $fquery = $DB->query("SELECT f.forum_id, f.forum_name, b.board_label
  1967. FROM exp_forums f, exp_forum_boards b
  1968. WHERE f.forum_is_cat = 'n'
  1969. AND b.board_id = f.board_id
  1970. ORDER BY b.board_label asc, forum_order asc");
  1971. if ($fquery->num_rows == 0)
  1972. {
  1973. $r .= $DSP->qdiv('itemWrapper', BR.$DSP->qdiv('highlight', $LANG->line('forums_unavailable', 'title')));
  1974. }
  1975. else
  1976. {
  1977. if (isset($entry_id) AND $entry_id != 0 AND $which == 'save')
  1978. {
  1979. if ( ! isset($forum_topic_id))
  1980. {
  1981. $fquery2 = $DB->query("SELECT forum_topic_id FROM exp_weblog_titles WHERE entry_id = '{$entry_id}'");
  1982. $forum_topic_id = $fquery2->row['forum_topic_id'];
  1983. }
  1984. $r .= $DSP->input_hidden('forum_topic_id', $forum_topic_id);
  1985. }
  1986. $forum_title = ( ! $IN->GBL('forum_title')) ? '' : $IN->GBL('forum_title');
  1987. $forum_body = ( ! $IN->GBL('forum_body')) ? '' : $IN->GBL('forum_body');
  1988. $field_js = ($show_button_cluster == 'y') ? "onFocus='setFieldName(this.name)'" : '';
  1989. $r .= $DSP->qdiv('itemWrapper',
  1990. $DSP->qdiv('itemTitle', $LANG->line('forum_title', 'forum_title')).
  1991. $DSP->input_text('forum_title', $forum_title, '20', '100', 'input', '400px')
  1992. );
  1993. $r .= $DSP->qdiv('itemWrapper',
  1994. $DSP->qdiv('itemTitle', $LANG->line('forum_body', 'forum_body')).
  1995. $DSP->input_textarea('forum_body', $forum_body, 10, 'textarea', '99%', $field_js, $convert_ascii)
  1996. );
  1997. $r .= $DSP->qspan('itemTitle', $LANG->line('forum', 'forum')).NBS.$DSP->input_select_header('forum_id');
  1998. foreach ($fquery->result as $forum)
  1999. {
  2000. $r .= $DSP->input_select_option($forum['forum_id'], $forum['board_label'].": ".$forum['forum_name'], (($forum['forum_id'] == $IN->GBL('forum_id')) ? 1 : ''));
  2001. }
  2002. $r .= $DSP->input_select_footer();
  2003. $forum_topic_id = ( ! isset($_POST['forum_topic_id'])) ? '' : $_POST['forum_topic_id'];
  2004. $r .= $DSP->qdiv('itemWrapper',
  2005. $DSP->qdiv('itemTitle', $LANG->line('forum_topic_id', 'forum_topic_id')).
  2006. $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('forum_topic_id_exitsts'))).
  2007. $DSP->input_text('forum_topic_id', $forum_topic_id, '20', '12', 'input', '100px')
  2008. );
  2009. }
  2010. }
  2011. else
  2012. {
  2013. if ( ! isset($forum_topic_id))
  2014. {
  2015. $fquery = $DB->query("SELECT forum_topic_id FROM exp_weblog_titles WHERE entry_id = '{$entry_id}'");
  2016. $forum_topic_id = $fquery->row['forum_topic_id'];
  2017. }
  2018. if ($forum_topic_id != 0)
  2019. {
  2020. $fquery = $DB->query("SELECT title FROM exp_forum_topics WHERE topic_id = '{$forum_topic_id}'");
  2021. $ftitle = ($fquery->num_rows == 0) ? '' : $fquery->row['title'];
  2022. $r .= $DSP->qdiv('itemWrapper',
  2023. $DSP->qdiv('itemTitle', $LANG->line('forum_title', 'forum_title')).
  2024. $DSP->qdiv('itemWrapper', $ftitle)
  2025. );
  2026. }
  2027. $r .= $DSP->qdiv('itemWrapper',
  2028. $DSP->qdiv('itemTitle', $LANG->line('forum_topic_id', 'forum_topic_id')).
  2029. $DSP->qdiv('itemWrapper', $LANG->line('forum_topic_id_info')).
  2030. $DSP->input_text('forum_topic_id', $forum_topic_id, '20', '12', 'input', '100px')
  2031. );
  2032. }
  2033. $r .= '</td>';
  2034. $r .= "</tr></table>";
  2035. $r .= $DSP->div_c();
  2036. $r .= $DSP->div_c();
  2037. $r .= $DSP->div_c();
  2038. $r .= $DSP->div_c();
  2039. }
  2040. /** ----------------------------------------------
  2041. /** PAGES BLOCK
  2042. /** ---------------------------------------------*/
  2043. if ($show_pages_cluster == 'y' AND ($pages = $PREFS->ini('site_pages')) !== FALSE)
  2044. {
  2045. $r .= '<div id="blockpages" style="display: none; padding:0; margin:0;">';
  2046. $r .= NL.'<div class="publishTabWrapper">';
  2047. $r .= NL.'<div class="publishBox">';
  2048. $r .= NL.'<div class="publishInnerPad">';
  2049. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  2050. $r .= NL.'<td class="publishItemWrapper">'.BR;
  2051. $pages_uri = '';
  2052. $pages_template_id = '';
  2053. if ($entry_id != '' && isset($pages['uris'][$entry_id]))
  2054. {
  2055. $pages_uri = $pages['uris'][$entry_id];
  2056. $pages_template_id = $pages['templates'][$entry_id];
  2057. }
  2058. else
  2059. {
  2060. $query = $DB->query("SELECT configuration_value FROM exp_pages_configuration
  2061. WHERE configuration_name = '".$DB->escape_str('template_weblog_'.$weblog_id)."'
  2062. AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  2063. if ($query->num_rows > 0)
  2064. {
  2065. $pages_template_id = $query->row['configuration_value'];
  2066. }
  2067. }
  2068. $pages_uri = ( ! $IN->GBL('pages_uri')) ? $pages_uri : $IN->GBL('pages_uri');
  2069. $pages_template_id = ( ! $IN->GBL('pages_template_id')) ? $pages_template_id : $IN->GBL('pages_template_id');
  2070. if ($pages_uri == '')
  2071. {
  2072. /* A bit of JS to give them an example of what we want for the Pages URI value */
  2073. $r .= $DSP->qdiv('itemWrapper',
  2074. $DSP->qspan('itemTitle', $LANG->line('pages_uri', 'pages_uri').':').
  2075. NBS.
  2076. "<input dir='ltr' size='20' maxlength='100' style='width:400px; color: #666' type='text' name='pages_uri' id='pages_uri' ".
  2077. "value='/example/pages/uri/' onfocus='if(this.value == \"/example/pages/uri/\"){this.style.color=\"#000\";this.value=\"\"}' class='input' />"
  2078. );
  2079. }
  2080. else
  2081. {
  2082. $r .= $DSP->qdiv('itemWrapper',
  2083. $DSP->qspan('itemTitle', $LANG->line('pages_uri', 'pages_uri').':').
  2084. NBS.
  2085. $DSP->input_text('pages_uri', $pages_uri, '20', '100', 'input', '400px')
  2086. );
  2087. }
  2088. $r .= BR.
  2089. $DSP->qspan('itemTitle', $LANG->line('template', 'pages_template_id').':').
  2090. NBS.
  2091. $DSP->input_select_header('pages_template_id');
  2092. $sql = "SELECT tg.group_name, t.template_id, t.template_name
  2093. FROM exp_template_groups tg, exp_templates t
  2094. WHERE tg.group_id = t.group_id
  2095. AND tg.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ";
  2096. if (USER_BLOG == TRUE)
  2097. {
  2098. $sql .= "AND tg.group_id = '".$SESS->userdata['tmpl_group_id']."' ";
  2099. }
  2100. else
  2101. {
  2102. $sql .= "AND tg.is_user_blog = 'n' ";
  2103. }
  2104. $sql .= " ORDER BY tg.group_name, t.template_name";
  2105. $tquery = $DB->query($sql);
  2106. foreach ($tquery->result as $template)
  2107. {
  2108. $r .= $DSP->input_select_option($template['template_id'], $template['group_name'].'/'.$template['template_name'], (($template['template_id'] == $pages_template_id) ? 1 : ''));
  2109. }
  2110. $r .= $DSP->input_select_footer();
  2111. $r .= '</td>';
  2112. $r .= "</tr></table>";
  2113. $r .= $DSP->div_c();
  2114. $r .= $DSP->div_c();
  2115. $r .= $DSP->div_c();
  2116. $r .= $DSP->div_c();
  2117. }
  2118. // -------------------------------------------
  2119. // 'publish_form_new_tabs_block' hook.
  2120. // - Allows adding of new tabs' blocks to the submission form
  2121. //
  2122. if ($EXT->active_hook('publish_form_new_tabs_block') === TRUE)
  2123. {
  2124. $r .= $EXT->call_extension('publish_form_new_tabs_block', $weblog_id);
  2125. }
  2126. //
  2127. // -------------------------------------------
  2128. /** --------------------------------
  2129. /** SHOW ALL TAB - Goes after all the others
  2130. /** --------------------------------*/
  2131. if ($show_show_all_cluster == 'y')
  2132. {
  2133. $r .= '<div id="blockshow_all" style="display: none; padding:0; margin:0;"></div>';
  2134. }
  2135. /** --------------------------------
  2136. /** MAIN PUBLISHING FORM
  2137. /** --------------------------------*/
  2138. $r .= NL."<table border='0' cellpadding='0' cellspacing='0' style='width:100%'><tr><td class='publishBox'>";
  2139. $r .= NL."<table border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr><td>";
  2140. $r .= $DSP->div('publishTitleCluster');
  2141. $r .= $DSP->qdiv('itemWrapper',
  2142. $DSP->qdiv('itemTitle', $DSP->required().NBS.$LANG->line('title', 'title')).
  2143. $DSP->input_text('title', $title, '20', '100', 'input', '100%', (($entry_id == '') ? 'onkeyup="liveUrlTitle();"' : ''), $convert_ascii)
  2144. );
  2145. /** --------------------------------
  2146. /** "URL title" input Field
  2147. /** --------------------------------*/
  2148. if ($show_url_title == 'n' AND $this->url_title_error === FALSE)
  2149. {
  2150. $r .= $DSP->input_hidden('url_title', $url_title);
  2151. }
  2152. else
  2153. {
  2154. $r .= $DSP->qdiv('itemWrapper',
  2155. $DSP->qdiv('itemTitle', $LANG->line('url_title', 'url_title')).
  2156. $DSP->input_text('url_title', $url_title, '20', '75', 'input', '100%')
  2157. );
  2158. }
  2159. $r .= $DSP->div_c();
  2160. $r .= '</td>';
  2161. $r .= '<td style="width:350px;padding-top: 4px;" valign="top">';
  2162. /** --------------------------------
  2163. /** Submit/Preview buttons
  2164. /** --------------------------------*/
  2165. $r .= $DSP->div('submitBox').$DSP->input_submit($LANG->line('preview'), 'preview').NBS.$DSP->input_submit($LANG->line('quick_save'), 'save').NBS;
  2166. $r .= ($IN->GBL('C') == 'publish') ? $DSP->input_submit($LANG->line('submit'), 'submit') : $DSP->input_submit($LANG->line('update'), 'submit');
  2167. $r .= $DSP->div_c();
  2168. /** --------------------------------
  2169. /** Upload link
  2170. /** --------------------------------*/
  2171. $up_img = '<img src="'.PATH_CP_IMG.'upload_file.gif" border="0" width="16" height="16" alt="'.$LANG->line('file_upload').'" />';
  2172. $r .= $DSP->div('uploadBox');
  2173. // -------------------------------------------
  2174. // 'publish_form_upload_link' hook.
  2175. // - Rewrite URL for Upload Link
  2176. //
  2177. if ($EXT->active_hook('publish_form_upload_link') === TRUE)
  2178. {
  2179. $r .= $EXT->call_extension('publish_form_upload_link', $up_img);
  2180. }
  2181. else
  2182. {
  2183. $r .= $DSP->anchorpop(BASE.AMP.'C=publish'.AMP.'M=file_upload_form'.AMP.'field_group='.$field_group.AMP.'Z=1', $up_img.'&nbsp;'.$LANG->line('upload_file'), '520', '600');
  2184. }
  2185. //
  2186. // -------------------------------------------
  2187. $r .= NBS.$DSP->div_c();
  2188. $r .= "</td></tr></table>";
  2189. /** --------------------------------
  2190. /** HTML formatting buttons
  2191. /** --------------------------------*/
  2192. if ($show_button_cluster == 'y')
  2193. {
  2194. $r .= $this->html_formatting_buttons('', $field_group, FALSE, $weblog_allow_img_urls);
  2195. }
  2196. else
  2197. {
  2198. $r .= $this->insert_javascript();
  2199. }
  2200. /** --------------------------------
  2201. /** Custom Fields
  2202. /** --------------------------------*/
  2203. $r .= $DSP->qdiv('publishLine');
  2204. if ($this->SPELL->enabled === TRUE)
  2205. {
  2206. $r .= '<div id="spellcheck_popup" class="wordSuggestion" style="position:absolute;visibility:hidden;"></div>'.NL; // Spell Check Word Suggestion Box
  2207. }
  2208. $expand = '<img src="'.PATH_CP_IMG.'expand.gif" border="0" width="10" height="10" alt="Expand" />';
  2209. $collapse = '<img src="'.PATH_CP_IMG.'collapse.gif" border="0" width="10" height="10" alt="Collapse" />';
  2210. foreach ($field_query->result as $row)
  2211. {
  2212. switch ($which)
  2213. {
  2214. case 'preview' :
  2215. $field_data = ( ! isset( $_POST['field_id_'.$row['field_id']] )) ? '' : $_POST['field_id_'.$row['field_id']];
  2216. $field_fmt = ( ! isset( $_POST['field_ft_'.$row['field_id']] )) ? $row['field_fmt'] : $_POST['field_ft_'.$row['field_id']];
  2217. break;
  2218. case 'save' :
  2219. $field_data = ( ! isset( $_POST['field_id_'.$row['field_id']] )) ? '' : $_POST['field_id_'.$row['field_id']];
  2220. $field_fmt = ( ! isset( $_POST['field_ft_'.$row['field_id']] )) ? $row['field_fmt'] : $_POST['field_ft_'.$row['field_id']];
  2221. break;
  2222. case 'edit' :
  2223. $field_data = ( ! isset( $result->row['field_id_'.$row['field_id']] )) ? '' : $result->row['field_id_'.$row['field_id']];
  2224. $field_fmt = ( ! isset( $result->row['field_ft_'.$row['field_id']] )) ? $row['field_fmt'] : $result->row['field_ft_'.$row['field_id']];
  2225. break;
  2226. default :
  2227. $tb_url = ( ! isset($_GET['tb_url'])) ? '' : $_GET['tb_url'];
  2228. $tb_field = ( ! isset($_GET['field_id_'.$row['field_id']])) ? '' : $_GET['field_id_'.$row['field_id']];
  2229. $field_data = ( ! isset( $_GET['field_id_'.$row['field_id']] )) ? '' : $this->bm_qstr_decode($tb_url."\n\n".$tb_field);
  2230. $field_fmt = $row['field_fmt'];
  2231. break;
  2232. }
  2233. $required = ($row['field_required'] == 'n') ? '' : $DSP->required().NBS;
  2234. $text_direction = ($row['field_text_direction'] == 'rtl') ? 'rtl' : 'ltr';
  2235. $flink = $DSP->qdiv('itemWrapper', '<label for="field_id_'.
  2236. $row['field_id'].
  2237. '"><a href="javascript:void(0);" onclick="showhide_field(\''.
  2238. $row['field_id'].
  2239. '\');return false;">{ICON}<b>'.
  2240. NBS.NBS.$required.$row['field_label'].
  2241. '</b></a></label>');
  2242. // Enclosing DIV for each row
  2243. $r .= $DSP->div('publishRows');
  2244. if ($row['field_is_hidden'] == 'y')
  2245. {
  2246. $r .= '<div id="field_pane_off_'.$row['field_id'].'" style="display: block; padding:0; margin:0;">';
  2247. $r .= str_replace('{ICON}', $expand, $flink);
  2248. $r .= $DSP->div_c();
  2249. $r .= '<div id="field_pane_on_'.$row['field_id'].'" style="display: none; padding:0; margin:0;">';
  2250. $r .= str_replace('{ICON}', $collapse, $flink);
  2251. }
  2252. else
  2253. {
  2254. $r .= '<div id="field_pane_off_'.$row['field_id'].'" style="display: none; padding:0; margin:0;">';
  2255. $r .= str_replace('{ICON}', $expand, $flink);
  2256. $r .= $DSP->div_c();
  2257. $r .= '<div id="field_pane_on_'.$row['field_id'].'" style="display: block; padding:0; margin:0;">';
  2258. $r .= str_replace('{ICON}', $collapse, $flink);
  2259. }
  2260. /** --------------------------------
  2261. /** Instructions for Field
  2262. /** --------------------------------*/
  2263. if (trim($row['field_instructions']) != '')
  2264. {
  2265. $r .= $DSP->qdiv('paddedWrapper',
  2266. $DSP->qspan('defaultBold', $LANG->line('instructions')).
  2267. $row['field_instructions']);
  2268. }
  2269. /** --------------------------------
  2270. /** Textarea field types
  2271. /** --------------------------------*/
  2272. if ($row['field_type'] == 'textarea')
  2273. {
  2274. $rows = ( ! isset($row['field_ta_rows'])) ? '10' : $row['field_ta_rows'];
  2275. $field_js = ($show_button_cluster == 'y') ? "onFocus='setFieldName(this.name)'" : '';
  2276. // This table fixes a Safari bug. Kill the table once Safari has fixed it.
  2277. $r .= "<table border='0' cellpadding='0' cellspacing='0' style='width:99%;margin-bottom:0;'><tr><td>";
  2278. // -------------------------------------------
  2279. // 'publish_form_field_textarea' hook.
  2280. // - Allows modification of the field textareas
  2281. //
  2282. if ($EXT->active_hook('publish_form_field_textarea') === TRUE)
  2283. {
  2284. $r .= $EXT->call_extension('publish_form_field_textarea', $row['field_id'], $field_data, $rows, $field_js, $convert_ascii, $text_direction);
  2285. }
  2286. else
  2287. {
  2288. $r .= $DSP->input_textarea('field_id_'.$row['field_id'], $field_data, $rows, 'textarea', '100%', $field_js, $convert_ascii, $text_direction);
  2289. }
  2290. //
  2291. // -------------------------------------------
  2292. if ($row['field_show_fmt'] == 'y')
  2293. {
  2294. $r .= $this->text_formatting_buttons($row['field_id'], $field_fmt);
  2295. }
  2296. else
  2297. {
  2298. $r .= $DSP->input_hidden('field_ft_'.$row['field_id'], $field_fmt);
  2299. }
  2300. // Safari Fix
  2301. $r .= "</td></tr></table>";
  2302. /** --------------------------------
  2303. /** Smileys Pane
  2304. /** --------------------------------*/
  2305. if ($row['field_show_fmt'] == 'y')
  2306. {
  2307. $r .= '<div id="smileys_'.$row['field_id'].'" style="display: none; padding:0; margin:0;">';
  2308. $r .= NL."<table border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr><td>";
  2309. $r .= NL.'<div class="clusterBox">';
  2310. $r .= NL.'<div class="publishItemWrapper">';
  2311. $r .= $this->fetch_emoticons($row['field_id']);
  2312. $r .= NL.'</div>';
  2313. $r .= NL.'</div>';
  2314. $r .= $DSP->td_c();
  2315. $r .= $DSP->tr_c();
  2316. $r .= $DSP->table_c();
  2317. $r .= NL.'</div>';
  2318. /** --------------------------------
  2319. /** Glossary Pane
  2320. /** --------------------------------*/
  2321. $r .= '<div id="glossary_'.$row['field_id'].'" style="display: none; padding:0; margin:0;">';
  2322. $r .= NL."<table border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr><td>";
  2323. $r .= $this->fetch_glossary($row['field_id']);
  2324. $r .= $DSP->td_c();
  2325. $r .= $DSP->tr_c();
  2326. $r .= $DSP->table_c();
  2327. $r .= NL.'</div>';
  2328. /** --------------------------------
  2329. /** Spell Check Pane
  2330. /** --------------------------------*/
  2331. if ($this->SPELL->enabled === TRUE)
  2332. {
  2333. $spacer = NBS.NBS.NBS.NBS.'|'.NBS.NBS.NBS.NBS;
  2334. $r .= '<div id="spellcheck_field_id_'.$row['field_id'].'" style="display: none; padding:0; margin:0;">';
  2335. $r .= NL."<table border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr><td>";
  2336. $r .= NL.'<div class="clusterBox">';
  2337. $r .= NL.'<div class="publishItemWrapper">';
  2338. $r .= $DSP->div('highlight').$LANG->line('spell_check');
  2339. $r .= '<span id="spellcheck_hidden_field_id_'.$row['field_id'].'" style="visibility:hidden;">'.$spacer;
  2340. $r .= '<a href="javascript:void(0);" onclick="SP_saveSpellCheck();return false">';
  2341. $r .= $LANG->line('save_spellcheck').'</a>'.$spacer;
  2342. $r .= '<a href="javascript:void(0);" onclick="SP_revertToOriginal();return false">';
  2343. $r .= $LANG->line('revert_spellcheck').'</a></span>';
  2344. $r .= $DSP->div_c();
  2345. $r .= BR.BR;
  2346. $r .= '<iframe src="'.BASE.AMP.'C=publish'.AMP.'M=spellcheck_iframe" width="100%" style="display:none; border:1px solid #6600CC;" id="spellcheck_frame_field_id_'.$row['field_id'].'" name="spellcheck_frame_field_id_'.$row['field_id'].'"></iframe>';
  2347. $r .= NL.'</div>';
  2348. $r .= NL.'</div>';
  2349. $r .= $DSP->td_c();
  2350. $r .= $DSP->tr_c();
  2351. $r .= $DSP->table_c();
  2352. $r .= NL.'</div>';
  2353. }
  2354. }
  2355. }
  2356. /** --------------------------------
  2357. /** Date field types
  2358. /** --------------------------------*/
  2359. elseif ($row['field_type'] == 'date')
  2360. {
  2361. if ( ! class_exists('js_calendar'))
  2362. {
  2363. if (include_once(PATH_LIB.'js_calendar'.EXT))
  2364. {
  2365. $CAL = new js_calendar();
  2366. $DSP->extra_header .= $CAL->calendar();
  2367. }
  2368. }
  2369. // This table fixes a Safari bug. Kill the table once Safari has fixed it.
  2370. $r .= "<table border='0' cellpadding='0' cellspacing='0' style='margin-bottom:0;'><tr><td>";
  2371. $date_field = 'field_id_'.$row['field_id'];
  2372. $date_local = 'field_dt_'.$row['field_id'];
  2373. if ($field_data == 0)
  2374. $field_data = '';
  2375. $dtwhich = $which;
  2376. if (isset($_POST[$date_field]))
  2377. {
  2378. $field_data = $_POST[$date_field];
  2379. $dtwhich = ($which != 'save') ? 'preview' : '';
  2380. }
  2381. $custom_date = '';
  2382. $localize = FALSE;
  2383. if ($dtwhich != 'preview' OR $submission_error != '')
  2384. {
  2385. $localize = TRUE;
  2386. if ($field_data != '' AND isset($result))
  2387. {
  2388. if (isset($result->row['field_dt_'.$row['field_id']]) AND $result->row['field_dt_'.$row['field_id']] != '')
  2389. {
  2390. $field_data = $LOC->offset_entry_dst($field_data, $dst_enabled);
  2391. $field_data = $LOC->simpl_offset($field_data, $result->row['field_dt_'.$row['field_id']]);
  2392. $localize = FALSE;
  2393. }
  2394. }
  2395. if ($field_data != '')
  2396. $custom_date = $LOC->set_human_time($field_data, $localize);
  2397. $cal_date = ($LOC->set_localized_time($field_data) * 1000);
  2398. }
  2399. else
  2400. {
  2401. $custom_date = $_POST[$date_field];
  2402. $cal_date = ($custom_date != '') ? ($LOC->set_localized_time($LOC->convert_human_date_to_gmt($custom_date)) * 1000) : ($LOC->set_localized_time() * 1000);
  2403. }
  2404. /** --------------------------------
  2405. /** JavaScript Calendar
  2406. /** --------------------------------*/
  2407. $cal_img = '<a href="javascript:void(0);" onClick="showhide_item(\'calendar'.$date_field.'\');"><img src="'.PATH_CP_IMG.'calendar.gif" border="0" width="16" height="16" alt="'.$LANG->line('calendar').'" /></a>';
  2408. $r .= $DSP->input_text($date_field, $custom_date, '18', '23', 'input', '150px', ' onkeyup="update_calendar(\''.$date_field.'\', this.value);" ', $text_direction).$cal_img;
  2409. $r .= '<div id="calendar'.$date_field.'" style="display:none;margin:4px 0 0 0;padding:0;">';
  2410. $xmark = ($custom_date == '') ? 'false' : 'true';
  2411. $r .= NL.'<script type="text/javascript">
  2412. var '.$date_field .' = new calendar(
  2413. "'.$date_field.'",
  2414. new Date('.$cal_date.'),
  2415. '.$xmark.'
  2416. );
  2417. document.write('.$date_field.'.write());
  2418. </script>'.NL;
  2419. $r .= '</div>';
  2420. $r .= $DSP->div_c();
  2421. $r .= $DSP->div_c();
  2422. $localized = ( ! isset($_POST['field_offset_'.$row['field_id']])) ? (($localize == FALSE) ? 'n' : 'y') : $_POST['field_offset_'.$row['field_id']];
  2423. $r .= $DSP->div('itemWrapper').$DSP->div('lightLinks');
  2424. $r .= $DSP->input_select_header('field_offset_'.$row['field_id']);
  2425. $r .= $DSP->input_select_option('y', $LANG->line('localized_date'), ($localized == 'y') ? 1 : 0);
  2426. $r .= $DSP->input_select_option('n', $LANG->line('fixed_date'), ($localized == 'n') ? 1 : 0);
  2427. $r .= $DSP->input_select_footer().NBS.NBS;
  2428. $r .= '<a href="javascript:void(0);" onClick="set_to_now(\''.$date_field.'\', \''.$LOC->set_human_time($LOC->now).'\', \''.($LOC->set_localized_time() * 1000).'\')" >'.$LANG->line('today').'</a>'.NBS.NBS.'|'.NBS.NBS;
  2429. $r .= '<a href="javascript:void(0);" onClick="clear_field(\''.$date_field.'\');" >'.$LANG->line('clear').'</a>';
  2430. $r .= $DSP->div_c();
  2431. $r .= $DSP->div_c();
  2432. // Safari
  2433. $r .= "</td></tr></table>";
  2434. }
  2435. /** --------------------------------
  2436. /** Relationship field types
  2437. /** --------------------------------*/
  2438. elseif ($row['field_type'] == 'rel')
  2439. {
  2440. // This table fixes a Safari bug. Kill the table once Safari has fixed it.
  2441. $r .= "<table border='0' cellpadding='0' cellspacing='0' style='margin-bottom:0;'><tr><td>";
  2442. if ($row['field_related_to'] == 'blog')
  2443. {
  2444. $relto = 'exp_weblog_titles';
  2445. $relid = 'weblog_id';
  2446. }
  2447. else
  2448. {
  2449. $relto = 'exp_gallery_entries';
  2450. $relid = 'gallery_id';
  2451. }
  2452. if ($row['field_related_orderby'] == 'date')
  2453. $row['field_related_orderby'] = 'entry_date';
  2454. $sql = "SELECT entry_id, title FROM ".$relto." WHERE ".$relid." = '".$DB->escape_str($row['field_related_id'])."' ";
  2455. $sql .= "ORDER BY ".$row['field_related_orderby']." ".$row['field_related_sort'];
  2456. if ($row['field_related_max'] > 0)
  2457. {
  2458. $sql .= " LIMIT ".$row['field_related_max'];
  2459. }
  2460. $relquery = $DB->query($sql);
  2461. if ($relquery->num_rows == 0)
  2462. {
  2463. $r .= $DSP->qdiv('highlight_alt', $LANG->line('no_related_entries'));
  2464. }
  2465. else
  2466. {
  2467. $relentry_id = '';
  2468. if ( ! isset($_POST['field_id_'.$row['field_id']]) OR $which == 'save')
  2469. {
  2470. $relentry = $DB->query("SELECT rel_child_id FROM exp_relationships WHERE rel_id = '".$DB->escape_str($field_data)."'");
  2471. if ($relentry->num_rows == 1)
  2472. {
  2473. $relentry_id = $relentry->row['rel_child_id'];
  2474. }
  2475. }
  2476. else
  2477. {
  2478. $relentry_id = $_POST['field_id_'.$row['field_id']];
  2479. }
  2480. $r .= $DSP->input_select_header('field_id_'.$row['field_id']);
  2481. $r .= $DSP->input_select_option('', '--', '', "dir='{$text_direction}'");
  2482. foreach ($relquery->result as $relrow)
  2483. {
  2484. $r .= $DSP->input_select_option($relrow['entry_id'],
  2485. $relrow['title'],
  2486. ($relentry_id == $relrow['entry_id']) ? 1 : 0,
  2487. "dir='{$text_direction}'");
  2488. }
  2489. $r .= $DSP->input_select_footer();
  2490. }
  2491. // Safari
  2492. $r .= "</td></tr></table>";
  2493. }
  2494. /** --------------------------------
  2495. /** Text input field types
  2496. /** --------------------------------*/
  2497. elseif ($row['field_type'] == 'text')
  2498. {
  2499. // This table fixes a Safari bug. Kill the table once Safari has fixed it.
  2500. $r .= "<table border='0' cellpadding='0' cellspacing='0' style='width:99%;margin-bottom:0;'><tr><td>";
  2501. // -------------------------------------------
  2502. // 'publish_form_field_text_input' hook.
  2503. // - Allows modification of the field text inputs
  2504. //
  2505. $field_js = ($show_button_cluster == 'y') ? "onFocus='setFieldName(this.name)'" : '';
  2506. if ($EXT->active_hook('publish_form_field_text_input') === TRUE)
  2507. {
  2508. $r .= $EXT->call_extension('publish_form_field_text_input', $row['field_id'], $field_data, $row['field_maxl'], $field_js, $convert_ascii, $text_direction);
  2509. }
  2510. else
  2511. {
  2512. $r .= $DSP->input_text('field_id_'.$row['field_id'], $field_data, '50', $row['field_maxl'], 'input', '100%', $field_js, $convert_ascii, $text_direction);
  2513. }
  2514. //
  2515. // -------------------------------------------
  2516. if ($row['field_show_fmt'] == 'y')
  2517. {
  2518. $r .= $this->text_formatting_buttons($row['field_id'], $field_fmt);
  2519. }
  2520. else
  2521. {
  2522. $r .= $DSP->input_hidden('field_ft_'.$row['field_id'], $field_fmt);
  2523. }
  2524. // Safari
  2525. $r .= "</td></tr></table>";
  2526. }
  2527. /** --------------------------------
  2528. /** Drop-down lists
  2529. /** --------------------------------*/
  2530. elseif ($row['field_type'] == 'select')
  2531. {
  2532. // -------------------------------------------
  2533. // 'publish_form_field_select_header' hook.
  2534. // - Allows modification of the field select header
  2535. //
  2536. if ($EXT->active_hook('publish_form_field_select_header') === TRUE)
  2537. {
  2538. $r .= $EXT->call_extension('publish_form_field_select_header', $row['field_id'], $field_data, $text_direction);
  2539. }
  2540. else
  2541. {
  2542. $r .= $DSP->input_select_header('field_id_'.$row['field_id'], '', '');
  2543. }
  2544. //
  2545. // -------------------------------------------
  2546. if ($row['field_pre_populate'] == 'n')
  2547. {
  2548. foreach (explode("\n", trim($row['field_list_items'])) as $v)
  2549. {
  2550. $v = trim($v);
  2551. $selected = ($v == $field_data) ? 1 : '';
  2552. // -------------------------------------------
  2553. // 'publish_form_field_select_option' hook.
  2554. // - Allows modification of the field selection options
  2555. // - Version 1.4.2 : Added $field_data variable
  2556. //
  2557. if ($EXT->active_hook('publish_form_field_select_option') === TRUE)
  2558. {
  2559. $r .= $EXT->call_extension('publish_form_field_select_option', $v, $v, $selected, $field_data);
  2560. }
  2561. else
  2562. {
  2563. $v = $REGX->form_prep($v);
  2564. $r .= $DSP->input_select_option($v, $v, $selected, "dir='{$text_direction}'");
  2565. }
  2566. //
  2567. // -------------------------------------------
  2568. }
  2569. }
  2570. else
  2571. {
  2572. // We need to pre-populate this menu from an another weblog custom field
  2573. $pop_query = $DB->query("SELECT field_id_".$row['field_pre_field_id']." FROM exp_weblog_data WHERE weblog_id = ".$row['field_pre_blog_id']."");
  2574. $r .= $DSP->input_select_option('', '--', '', $text_direction);
  2575. if ($pop_query->num_rows > 0)
  2576. {
  2577. foreach ($pop_query->result as $prow)
  2578. {
  2579. $selected = ($prow['field_id_'.$row['field_pre_field_id']] == $field_data) ? 1 : '';
  2580. $pretitle = substr($prow['field_id_'.$row['field_pre_field_id']], 0, 110);
  2581. $pretitle = preg_replace("/\r\n|\r|\n|\t/", ' ', $pretitle);
  2582. $pretitle = $REGX->form_prep($pretitle);
  2583. $r .= $DSP->input_select_option($REGX->form_prep($prow['field_id_'.$row['field_pre_field_id']]), $pretitle, $selected, $text_direction);
  2584. }
  2585. }
  2586. }
  2587. $r .= $DSP->input_select_footer();
  2588. if ($row['field_show_fmt'] == 'y')
  2589. {
  2590. $r .= $this->text_formatting_buttons($row['field_id'], $field_fmt);
  2591. }
  2592. else
  2593. {
  2594. $r .= $DSP->input_hidden('field_ft_'.$row['field_id'], $field_fmt);
  2595. }
  2596. }
  2597. /** ---------------------------------------------
  2598. /** Custom Field Types - Created By Extensions
  2599. /** ---------------------------------------------*/
  2600. else
  2601. {
  2602. /* -------------------------------------------
  2603. /* 'publish_form_field_unique' hook.
  2604. /* - Allows adding of unique custom fields via extensions
  2605. /* - Added 1.4.2
  2606. */
  2607. if ($EXT->active_hook('publish_form_field_unique') === TRUE)
  2608. {
  2609. $r .= $EXT->call_extension('publish_form_field_unique', $row, $field_data, $text_direction);
  2610. }
  2611. /*
  2612. /* -------------------------------------------*/
  2613. }
  2614. // Close Div - SHOW/HIDE FIELD PANES
  2615. $r .= $DSP->div_c();
  2616. // Close outer DIV
  2617. $r .= $DSP->div_c();
  2618. }
  2619. // -------------------------------------------
  2620. // 'publish_form_end' hook.
  2621. // - Allows adding to end of submission form
  2622. //
  2623. if ($EXT->active_hook('publish_form_end') === TRUE)
  2624. {
  2625. $r .= $EXT->call_extension('publish_form_end', $weblog_id);
  2626. }
  2627. //
  2628. // -------------------------------------------
  2629. /** ----------------------------------------------
  2630. /** END PUBLISH FORM BLOCK
  2631. /** ---------------------------------------------*/
  2632. $r .= "</td></tr></table>";
  2633. $r .= $DSP->form_close();
  2634. if ($this->direct_return == TRUE)
  2635. {
  2636. return $r;
  2637. }
  2638. $DSP->body = $r;
  2639. }
  2640. /* END */
  2641. /** -------------------------------------
  2642. /** Convert quotes in trackback titles
  2643. /** -------------------------------------*/
  2644. // This function converts any quotes found in RDF titles
  2645. // to entities. This is used in the trackback auto-discovery feature
  2646. // to prevent a bug that happens if weblog entry titles contain quotes
  2647. function convert_tb_title_entities($matches)
  2648. {
  2649. $matches['2'] = trim($matches['2']);
  2650. $matches['2'] = preg_replace("/^\"/", '', $matches['2']);
  2651. $matches['2'] = preg_replace("/\"$/", '', $matches['2']);
  2652. $matches['2'] = str_replace("\"", "&quot;", $matches['2']);
  2653. return $matches['1']."\"".$matches['2']."\"\n".$matches['3'];
  2654. }
  2655. /* END */
  2656. /** -------------------------------------
  2657. /** Bookmarklet query string decode
  2658. /** -------------------------------------*/
  2659. function bm_qstr_decode($str)
  2660. {
  2661. global $REGX;
  2662. $str = str_replace("%20", " ", $str);
  2663. $str = str_replace("%uFFA5", "&#8226;", $str);
  2664. $str = str_replace("%uFFCA", " ", $str);
  2665. $str = str_replace("%uFFC1", "-", $str);
  2666. $str = str_replace("%uFFC9", "...", $str);
  2667. $str = str_replace("%uFFD0", "-", $str);
  2668. $str = str_replace("%uFFD1", "-", $str);
  2669. $str = str_replace("%uFFD2", "\"", $str);
  2670. $str = str_replace("%uFFD3", "\"", $str);
  2671. $str = str_replace("%uFFD4", "\'", $str);
  2672. $str = str_replace("%uFFD5", "\'", $str);
  2673. $str = preg_replace("/\%u([0-9A-F]{4,4})/e","'&#'.base_convert('\\1',16,10).';'", $str);
  2674. $str = $REGX->xss_clean(stripslashes(urldecode($str)));
  2675. return $str;
  2676. }
  2677. /* END */
  2678. /** ----------------------------------------
  2679. /** Fetch the parent category ID
  2680. /** ----------------------------------------*/
  2681. function fetch_category_parents($cat_array = '')
  2682. {
  2683. global $DB, $PREFS;
  2684. if (count($cat_array) == 0)
  2685. {
  2686. return;
  2687. }
  2688. $sql = "SELECT parent_id FROM exp_categories WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND (";
  2689. foreach($cat_array as $val)
  2690. {
  2691. $sql .= " cat_id = '$val' OR ";
  2692. }
  2693. $sql = substr($sql, 0, -3).")";
  2694. $query = $DB->query($sql);
  2695. if ($query->num_rows == 0)
  2696. {
  2697. return;
  2698. }
  2699. $temp = array();
  2700. foreach ($query->result as $row)
  2701. {
  2702. if ($row['parent_id'] != 0)
  2703. {
  2704. $this->cat_parents[] = $row['parent_id'];
  2705. $temp[] = $row['parent_id'];
  2706. }
  2707. }
  2708. $this->fetch_category_parents($temp);
  2709. }
  2710. /** ---------------------------------------------------------------
  2711. /** Weblog entry submission handler
  2712. /** ---------------------------------------------------------------*/
  2713. // This function receives a new or edited weblog entry and
  2714. // stores it in the database. It also sends trackbacks and pings
  2715. //---------------------------------------------------------------
  2716. function submit_new_entry($cp_call = TRUE)
  2717. {
  2718. global $IN, $PREFS, $OUT, $LANG, $FNS, $LOC, $DSP, $DB, $SESS, $STAT, $REGX, $EXT;
  2719. $url_title = '';
  2720. $tb_format = 'xhtml';
  2721. $tb_errors = FALSE;
  2722. $ping_errors = FALSE;
  2723. $revision_post = $_POST;
  2724. $return_url = ( ! $IN->GBL('return_url', 'POST')) ? '' : $IN->GBL('return_url');
  2725. unset($_POST['return_url']);
  2726. if ($PREFS->ini('site_pages') !== FALSE)
  2727. {
  2728. $LANG->fetch_language_file('pages');
  2729. }
  2730. if ( ! $weblog_id = $IN->GBL('weblog_id', 'POST') OR ! is_numeric($weblog_id))
  2731. {
  2732. return false;
  2733. }
  2734. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  2735. /** ----------------------------------------------
  2736. /** Security check
  2737. /** ---------------------------------------------*/
  2738. if ( ! in_array($weblog_id, $assigned_weblogs))
  2739. {
  2740. return false;
  2741. }
  2742. // -------------------------------------------
  2743. // 'submit_new_entry_start' hook.
  2744. // - Add More Stuff to do when you first submit an entry
  2745. // - Added 1.4.2
  2746. //
  2747. $edata = $EXT->call_extension('submit_new_entry_start');
  2748. if ($EXT->end_script === TRUE) return;
  2749. //
  2750. // -------------------------------------------
  2751. /** -----------------------------
  2752. /** Does entry ID exist? And is valid for this weblog?
  2753. /** -----------------------------*/
  2754. if (($entry_id = $IN->GBL('entry_id', 'POST')) !== FALSE && is_numeric($entry_id))
  2755. {
  2756. // we grab the author_id now as we use it later for author validation
  2757. $query = $DB->query("SELECT entry_id, author_id FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($entry_id)."' AND weblog_id = '".$DB->escape_str($weblog_id)."'");
  2758. if ($query->num_rows != 1)
  2759. {
  2760. return FALSE;
  2761. }
  2762. else
  2763. {
  2764. $entry_id = $query->row['entry_id'];
  2765. $orig_author_id = $query->row['author_id'];
  2766. }
  2767. }
  2768. else
  2769. {
  2770. $entry_id = '';
  2771. }
  2772. /** -----------------------------
  2773. /** Weblog Switch?
  2774. /** -----------------------------*/
  2775. $old_weblog = '';
  2776. if (($new_weblog = $IN->GBL('new_weblog', 'POST')) !== FALSE && $new_weblog != $weblog_id)
  2777. {
  2778. $query = $DB->query("SELECT status_group, cat_group, field_group, weblog_id
  2779. FROM exp_weblogs
  2780. WHERE weblog_id IN ('".$DB->escape_str($weblog_id)."', '".$DB->escape_str($new_weblog)."')");
  2781. if ($query->num_rows == 2)
  2782. {
  2783. if ($query->result['0']['status_group'] == $query->result['1']['status_group'] &&
  2784. $query->result['0']['cat_group'] == $query->result['1']['cat_group'] &&
  2785. $query->result['0']['field_group'] == $query->result['1']['field_group'])
  2786. {
  2787. if ($SESS->userdata['group_id'] == 1)
  2788. {
  2789. $old_weblog = $weblog_id;
  2790. $weblog_id = $new_weblog;
  2791. }
  2792. else
  2793. {
  2794. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  2795. if (in_array($new_weblog, $assigned_weblogs))
  2796. {
  2797. $old_weblog = $weblog_id;
  2798. $weblog_id = $new_weblog;
  2799. }
  2800. }
  2801. }
  2802. }
  2803. }
  2804. /** -----------------------------
  2805. /** Fetch Weblog Prefs
  2806. /** -----------------------------*/
  2807. $query = $DB->query("SELECT blog_title, blog_url, comment_url, deft_status, enable_versioning, enable_qucksave_versioning, max_revisions, weblog_notify, weblog_notify_emails, ping_return_url, rss_url, tb_return_url, trackback_field, comment_system_enabled, trackback_system_enabled FROM exp_weblogs WHERE weblog_id = '".$weblog_id."'");
  2808. $blog_title = $REGX->ascii_to_entities($query->row['blog_title']);
  2809. $blog_url = $query->row['blog_url'];
  2810. $ping_url = ($query->row['ping_return_url'] == '') ? $query->row['blog_url'] : $query->row['ping_return_url'];
  2811. $tb_url = ($query->row['tb_return_url'] == '') ? $query->row['blog_url'] : $query->row['tb_return_url'];
  2812. $rss_url = $query->row['rss_url'];
  2813. $deft_status = $query->row['deft_status'];
  2814. $comment_url = $query->row['comment_url'];
  2815. $trackback_field = $query->row['trackback_field'];
  2816. $comment_system_enabled = $query->row['comment_system_enabled'];
  2817. $trackback_system_enabled = $query->row['trackback_system_enabled'];
  2818. $notify_address = ($query->row['weblog_notify'] == 'y' AND $query->row['weblog_notify_emails'] != '') ? $query->row['weblog_notify_emails'] : '';
  2819. $enable_versioning = $query->row['enable_versioning'];
  2820. $enable_qucksave_versioning = $query->row['enable_qucksave_versioning'];
  2821. $max_revisions = $query->row['max_revisions'];
  2822. /** -----------------------------
  2823. /** Error trapping
  2824. /** -----------------------------*/
  2825. $error = array();
  2826. // Fetch language file
  2827. $LANG->fetch_language_file('publish_ad');
  2828. /** ---------------------------------
  2829. /** No entry title? Assign error.
  2830. /** ---------------------------------*/
  2831. if ( ! $title = strip_tags(trim(stripslashes($IN->GBL('title', 'POST')))))
  2832. {
  2833. $error[] = $LANG->line('missing_title');
  2834. }
  2835. /** ---------------------------------------------
  2836. /** No date? Assign error.
  2837. /** ---------------------------------------------*/
  2838. if ( ! $IN->GBL('entry_date', 'POST'))
  2839. {
  2840. $error[] = $LANG->line('missing_date');
  2841. }
  2842. /** ---------------------------------------------
  2843. /** Convert the date to a Unix timestamp
  2844. /** ---------------------------------------------*/
  2845. $entry_date = $LOC->convert_human_date_to_gmt($IN->GBL('entry_date', 'POST'));
  2846. if ( ! is_numeric($entry_date))
  2847. {
  2848. // Localize::convert_human_date_to_gmt() returns verbose errors
  2849. if ($entry_date !== FALSE)
  2850. {
  2851. $error[] = $entry_date.NBS.NBS.'('.$LANG->line('entry_date').')';
  2852. }
  2853. else
  2854. {
  2855. $error[] = $LANG->line('invalid_date_formatting');
  2856. }
  2857. }
  2858. /** ---------------------------------------------
  2859. /** Convert expiration date to a Unix timestamp
  2860. /** ---------------------------------------------*/
  2861. if ( ! $IN->GBL('expiration_date', 'POST'))
  2862. {
  2863. $expiration_date = 0;
  2864. }
  2865. else
  2866. {
  2867. $expiration_date = $LOC->convert_human_date_to_gmt($IN->GBL('expiration_date', 'POST'));
  2868. if ( ! is_numeric($expiration_date))
  2869. {
  2870. // Localize::convert_human_date_to_gmt() returns verbose errors
  2871. if ($expiration_date !== FALSE)
  2872. {
  2873. $error[] = $expiration_date.NBS.NBS.'('.$LANG->line('expiration_date').')';
  2874. }
  2875. else
  2876. {
  2877. $error[] = $LANG->line('invalid_date_formatting');
  2878. }
  2879. }
  2880. }
  2881. /** ---------------------------------------------
  2882. /** Convert comment expiration date timestamp
  2883. /** ---------------------------------------------*/
  2884. if ( ! $IN->GBL('comment_expiration_date', 'POST'))
  2885. {
  2886. $comment_expiration_date = 0;
  2887. }
  2888. else
  2889. {
  2890. $comment_expiration_date = $LOC->convert_human_date_to_gmt($IN->GBL('comment_expiration_date', 'POST'));
  2891. if ( ! is_numeric($comment_expiration_date))
  2892. {
  2893. // Localize::convert_human_date_to_gmt() returns verbose errors
  2894. if ($comment_expiration_date !== FALSE)
  2895. {
  2896. $error[] = $comment_expiration_date.NBS.NBS.'('.$LANG->line('comment_expiration_date').')';
  2897. }
  2898. else
  2899. {
  2900. $error[] = $LANG->line('invalid_date_formatting');
  2901. }
  2902. }
  2903. }
  2904. /** --------------------------------------
  2905. /** Are all requred fields filled out?
  2906. /** --------------------------------------*/
  2907. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE field_required = 'y'");
  2908. if ($query->num_rows > 0)
  2909. {
  2910. foreach ($query->result as $row)
  2911. {
  2912. if (isset($_POST['field_id_'.$row['field_id']]) AND $_POST['field_id_'.$row['field_id']] == '')
  2913. {
  2914. $error[] = $LANG->line('custom_field_empty').NBS.$row['field_label'];
  2915. }
  2916. }
  2917. }
  2918. /** --------------------------------------
  2919. /** Are there any custom date fields?
  2920. /** --------------------------------------*/
  2921. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE field_type = 'date'");
  2922. if ($query->num_rows > 0)
  2923. {
  2924. foreach ($query->result as $row)
  2925. {
  2926. if (isset($_POST['field_id_'.$row['field_id']]) AND $_POST['field_id_'.$row['field_id']] != '')
  2927. {
  2928. $_POST['field_ft_'.$row['field_id']] = 'none';
  2929. $custom_date = $LOC->convert_human_date_to_gmt($_POST['field_id_'.$row['field_id']]);
  2930. if ( ! is_numeric($custom_date))
  2931. {
  2932. // Localize::convert_human_date_to_gmt() returns verbose errors
  2933. if ($custom_date !== FALSE)
  2934. {
  2935. $error[] = $custom_date.NBS.NBS.'('.$row['field_label'].')';
  2936. }
  2937. else
  2938. {
  2939. $error[] = $LANG->line('invalid_date_formatting');
  2940. }
  2941. }
  2942. else
  2943. {
  2944. $custom_date = $LOC->offset_entry_dst($custom_date, $IN->GBL('dst_enabled', 'POST'));
  2945. $_POST['field_id_'.$row['field_id']] = $custom_date;
  2946. if ( ! isset($_POST['field_offset_'.$row['field_id']]))
  2947. {
  2948. $_POST['field_dt_'.$row['field_id']] = '';
  2949. }
  2950. else
  2951. {
  2952. if ($_POST['field_offset_'.$row['field_id']] == 'y')
  2953. {
  2954. $_POST['field_dt_'.$row['field_id']] = '';
  2955. }
  2956. else
  2957. {
  2958. $_POST['field_dt_'.$row['field_id']] = $SESS->userdata('timezone');
  2959. }
  2960. }
  2961. }
  2962. }
  2963. }
  2964. }
  2965. /** ---------------------------------
  2966. /** Fetch xml-rpc ping server IDs
  2967. /** ---------------------------------*/
  2968. $ping_servers = array();
  2969. foreach ($_POST as $key => $val)
  2970. {
  2971. if (strstr($key, 'ping') AND ! is_array($val))
  2972. {
  2973. $ping_servers[] = $val;
  2974. unset($_POST[$key]);
  2975. }
  2976. }
  2977. /** -------------------------------------
  2978. /** Pre-process Trackback data
  2979. /** -------------------------------------*/
  2980. // If the weblog submission was via the bookmarklet we need to fetch the trackback URLs
  2981. $tb_auto_urls = '';
  2982. if ($IN->GBL('BK', 'GP'))
  2983. {
  2984. foreach ($_POST as $key => $val)
  2985. {
  2986. if (preg_match('#^TB_AUTO_#', $key))
  2987. {
  2988. $tb_auto_urls .= $val.NL;
  2989. }
  2990. }
  2991. }
  2992. // Join the manually submitted trackbacks with the auto-disovered ones
  2993. $trackback_urls = $IN->GBL('trackback_urls');
  2994. if ($tb_auto_urls != '')
  2995. {
  2996. $trackback_urls .= NL.$tb_auto_urls;
  2997. }
  2998. /** --------------------------------------
  2999. /** Is weblog data present?
  3000. /** --------------------------------------*/
  3001. // In order to send pings or trackbacks, the weblog needs a title and URL
  3002. if ($trackback_urls != '' && ($blog_title == '' || $tb_url == ''))
  3003. {
  3004. $error[] = $LANG->line('missing_weblog_data_for_pings');
  3005. }
  3006. if (count($ping_servers) > 0 && ($blog_title == '' || $ping_url == ''))
  3007. {
  3008. $error[] = $LANG->line('missing_weblog_data_for_pings');
  3009. }
  3010. /** --------------------------------------
  3011. /** Is the title unique?
  3012. /** --------------------------------------*/
  3013. if ($title != '')
  3014. {
  3015. /** ---------------------------------
  3016. /** Do we have a URL title?
  3017. /** ---------------------------------*/
  3018. // If not, create one from the title
  3019. $url_title = $IN->GBL('url_title');
  3020. if ( ! $url_title)
  3021. {
  3022. $url_title = $REGX->create_url_title($title, TRUE);
  3023. }
  3024. // Kill all the extraneous characters.
  3025. // We want the URL title to pure alpha text
  3026. if ($entry_id != '')
  3027. {
  3028. $url_query = $DB->query("SELECT url_title FROM exp_weblog_titles WHERE entry_id = '$entry_id'");
  3029. if ($url_query->row['url_title'] != $url_title)
  3030. {
  3031. $url_title = $REGX->create_url_title($url_title);
  3032. }
  3033. }
  3034. else
  3035. {
  3036. $url_title = $REGX->create_url_title($url_title);
  3037. }
  3038. // Is the url_title a pure number? If so we show an error.
  3039. if (is_numeric($url_title))
  3040. {
  3041. $this->url_title_error = TRUE;
  3042. $error[] = $LANG->line('url_title_is_numeric');
  3043. }
  3044. /** -------------------------------------
  3045. /** Is the URL Title empty? Can't have that
  3046. /** -------------------------------------*/
  3047. if (trim($url_title) == '')
  3048. {
  3049. $this->url_title_error = TRUE;
  3050. $error[] = $LANG->line('unable_to_create_url_title');
  3051. $msg = '';
  3052. foreach($error as $val)
  3053. {
  3054. $msg .= $DSP->qdiv('itemWrapper', $val);
  3055. }
  3056. if ($cp_call == TRUE)
  3057. {
  3058. return $this->new_entry_form('preview', $msg);
  3059. }
  3060. else
  3061. {
  3062. return $OUT->show_user_error('general', $error);
  3063. }
  3064. }
  3065. /** ---------------------------------
  3066. /** Is URL title unique?
  3067. /** ---------------------------------*/
  3068. // Field is limited to 75 characters, so trim url_title before querying
  3069. $url_title = substr($url_title, 0, 75);
  3070. $e_sql = '';
  3071. $sql = "SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title = '".$DB->escape_str($url_title)."' AND weblog_id = '$weblog_id'";
  3072. if ($entry_id != '')
  3073. {
  3074. $e_sql = " AND entry_id != '$entry_id'";
  3075. }
  3076. $query = $DB->query($sql);
  3077. if ($query->row['count'] > 0)
  3078. {
  3079. // We may need some room to add our numbers- trim url_title to 70 characters
  3080. $url_title = substr($url_title, 0, 70);
  3081. // Check again
  3082. $sql = "SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title = '".$DB->escape_str($url_title).
  3083. "' AND weblog_id = '$weblog_id'".$e_sql;
  3084. $query = $DB->query($sql);
  3085. if ($query->row['count'] > 0)
  3086. {
  3087. $url_create_error = FALSE;
  3088. $sql = "SELECT url_title, MID(url_title, ".(strlen($url_title) + 1).") + 1 AS next_suffix FROM ".
  3089. "exp_weblog_titles WHERE weblog_id = '".$weblog_id."' ".
  3090. "AND url_title REGEXP('".preg_quote($DB->escape_str($url_title))."[0-9]*$') ".
  3091. "AND weblog_id = '".$weblog_id."'".$e_sql." ORDER BY next_suffix DESC LIMIT 1";
  3092. $query = $DB->query($sql);
  3093. // Did something go tragically wrong?
  3094. if ($query->num_rows == 0)
  3095. {
  3096. $url_create_error = TRUE;
  3097. $error[] = $LANG->line('unable_to_create_url_title');
  3098. }
  3099. // Is the appended number going to kick us over the 75 character limit?
  3100. if ($query->row['next_suffix'] > 99999)
  3101. {
  3102. $url_create_error = TRUE;
  3103. $error[] = $LANG->line('url_title_not_unique');
  3104. }
  3105. if ($url_create_error == FALSE)
  3106. {
  3107. $url_title = $url_title.$query->row['next_suffix'];
  3108. // little double check for safety
  3109. $sql = "SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title = '".$DB->escape_str($url_title).
  3110. "' AND weblog_id = '$weblog_id'".$e_sql;
  3111. $query = $DB->query($sql);
  3112. if ($query->row['count'] > 0)
  3113. {
  3114. $error[] = $LANG->line('unable_to_create_url_title');
  3115. }
  3116. }
  3117. }
  3118. }
  3119. }
  3120. // Did they name the URL title "index"? That's a bad thing which we disallow
  3121. if ($url_title == 'index')
  3122. {
  3123. $this->url_title_error = TRUE;
  3124. $error[] = $LANG->line('url_title_is_index');
  3125. }
  3126. /** -------------------------------------
  3127. /** Validate Page URI
  3128. /** -------------------------------------*/
  3129. if ($PREFS->ini('site_pages') !== FALSE &&
  3130. $IN->GBL('pages_uri', 'POST') !== FALSE && $IN->GBL('pages_uri', 'POST') != '' &&
  3131. $IN->GBL('pages_uri', 'POST') != '/example/pages/uri/'
  3132. )
  3133. {
  3134. if ( ! is_numeric($IN->GBL('pages_template_id', 'POST')))
  3135. {
  3136. $error[] = $LANG->line('invalid_template');
  3137. }
  3138. $page_uri = preg_replace("#[^a-zA-Z0-9_\-/\.]+$#i", '', str_replace($PREFS->ini('site_url'), '', $IN->GBL('pages_uri')));
  3139. if ($page_uri !== $IN->GBL('pages_uri', 'POST'))
  3140. {
  3141. $error[] = $LANG->line('invalid_page_uri');
  3142. }
  3143. /** -------------------------------------
  3144. /** Check if Duplicate Page URI
  3145. /** - Do NOT delete this as the $static_pages variable is used further down
  3146. /** -------------------------------------*/
  3147. $static_pages = $PREFS->ini('site_pages');
  3148. $uris = $static_pages['uris'];
  3149. if ($entry_id != '')
  3150. {
  3151. unset($uris[$entry_id]);
  3152. }
  3153. if (in_array($IN->GBL('pages_uri', 'POST'), $uris))
  3154. {
  3155. $error[] = $LANG->line('duplicate_page_uri');
  3156. }
  3157. unset($uris);
  3158. }
  3159. /** ---------------------------------------
  3160. /** Validate Author ID
  3161. /** ---------------------------------------*/
  3162. $author_id = ( ! $IN->GBL('author_id', 'POST')) ? $SESS->userdata('member_id'): $IN->GBL('author_id', 'POST');
  3163. if ($author_id != $SESS->userdata['member_id'] && ! $DSP->allowed_group('can_edit_other_entries'))
  3164. {
  3165. $error[] = $LANG->line('not_authorized');
  3166. }
  3167. if (isset($orig_author_id) && $author_id != $orig_author_id && (! $DSP->allowed_group('can_edit_other_entries') OR ! $DSP->allowed_group('can_assign_post_authors')))
  3168. {
  3169. $error[] = $LANG->line('not_authorized');
  3170. }
  3171. if ($author_id != $SESS->userdata['member_id'] && $SESS->userdata['group_id'] != 1)
  3172. {
  3173. // we only need to worry about this if the author has changed
  3174. if (! isset($orig_author_id) OR $author_id != $orig_author_id)
  3175. {
  3176. if (! $DSP->allowed_group('can_assign_post_authors'))
  3177. {
  3178. $error[] = $LANG->line('not_authorized');
  3179. }
  3180. else
  3181. {
  3182. $allowed_authors = array();
  3183. $ss = "SELECT exp_members.member_id
  3184. FROM exp_members
  3185. LEFT JOIN exp_member_groups on exp_member_groups.group_id = exp_members.group_id
  3186. WHERE (exp_members.in_authorlist = 'y' OR exp_member_groups.include_in_authorlist = 'y')
  3187. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  3188. $query = $DB->query($ss);
  3189. if ($query->num_rows > 0)
  3190. {
  3191. foreach ($query->result as $row)
  3192. {
  3193. // Is this a "user blog"? If so, we'll only allow
  3194. // authors if they are assigned to this particular blog
  3195. if ($SESS->userdata['weblog_id'] != 0)
  3196. {
  3197. if ($row['weblog_id'] == $weblog_id)
  3198. {
  3199. $allowed_authors[] = $row['member_id'];
  3200. }
  3201. }
  3202. else
  3203. {
  3204. $allowed_authors[] = $row['member_id'];
  3205. }
  3206. }
  3207. }
  3208. if (! in_array($author_id, $allowed_authors))
  3209. {
  3210. $error[] = $LANG->line('invalid_author');
  3211. }
  3212. }
  3213. }
  3214. }
  3215. /** ---------------------------------------
  3216. /** Validate status
  3217. /** ---------------------------------------*/
  3218. $status = ($IN->GBL('status', 'POST') == FALSE) ? $deft_status : $IN->GBL('status', 'POST');
  3219. if ($SESS->userdata['group_id'] != 1)
  3220. {
  3221. $disallowed_statuses = array();
  3222. $valid_statuses = array();
  3223. $sq = "SELECT s.status_id, s.status
  3224. FROM exp_statuses AS s
  3225. LEFT JOIN exp_status_groups AS sg ON sg.group_id = s.group_id
  3226. LEFT JOIN exp_weblogs AS w ON w.status_group = sg.group_id
  3227. WHERE w.weblog_id = '".$DB->escape_str($weblog_id)."'";
  3228. $query = $DB->query($sq);
  3229. if ($query->num_rows > 0)
  3230. {
  3231. foreach ($query->result as $row)
  3232. {
  3233. $valid_statuses[$row['status_id']] = strtolower($row['status']); // lower case to match MySQL's case-insensitivity
  3234. }
  3235. }
  3236. $dsq = "SELECT exp_status_no_access.status_id, exp_statuses.status
  3237. FROM exp_status_no_access, exp_statuses
  3238. WHERE exp_statuses.status_id = exp_status_no_access.status_id
  3239. AND exp_status_no_access.member_group = '".$SESS->userdata['group_id']."'";
  3240. $query = $DB->query($dsq);
  3241. if ($query->num_rows > 0)
  3242. {
  3243. foreach ($query->result as $row)
  3244. {
  3245. $disallowed_statuses[$row['status_id']] = strtolower($row['status']); // lower case to match MySQL's case-insensitivity
  3246. }
  3247. $valid_statuses = array_diff_assoc($valid_statuses, $disallowed_statuses);
  3248. }
  3249. if (! in_array(strtolower($status), $valid_statuses))
  3250. {
  3251. // if there are no valid statuses, set to closed
  3252. $status = 'closed';
  3253. }
  3254. }
  3255. /** ---------------------------------
  3256. /** Do we have an error to display?
  3257. /** ---------------------------------*/
  3258. if (count($error) > 0)
  3259. {
  3260. $msg = '';
  3261. foreach($error as $val)
  3262. {
  3263. $msg .= $DSP->qdiv('itemWrapper', $val);
  3264. }
  3265. if ($cp_call == TRUE)
  3266. return $this->new_entry_form('preview', $msg);
  3267. else
  3268. return $OUT->show_user_error('general', $error);
  3269. }
  3270. /** ---------------------------------
  3271. /** Fetch catagories
  3272. /** ---------------------------------*/
  3273. // We do this first so we can destroy the category index from
  3274. // the $_POST array since we use a separate table to store categories in
  3275. if (isset($_POST['category']) AND is_array($_POST['category']))
  3276. {
  3277. foreach ($_POST['category'] as $cat_id)
  3278. {
  3279. $this->cat_parents[] = $cat_id;
  3280. }
  3281. if ($this->assign_cat_parent == TRUE)
  3282. {
  3283. $this->fetch_category_parents($_POST['category']);
  3284. }
  3285. }
  3286. unset($_POST['category']);
  3287. /** ---------------------------------
  3288. /** Fetch previously sent trackbacks
  3289. /** ---------------------------------*/
  3290. // If we are editing an existing entry, fetch the previously sent trackbacks
  3291. // and add the new trackback URLs to them
  3292. $sent_trackbacks = '';
  3293. if ($trackback_urls != '' AND $entry_id != '')
  3294. {
  3295. $sent_trackbacks = trim($trackback_urls)."\n";
  3296. $query = $DB->query("SELECT sent_trackbacks FROM exp_weblog_titles WHERE entry_id = '$entry_id'");
  3297. if ($query->num_rows > 0)
  3298. {
  3299. $sent_trackbacks = $query->row['sent_trackbacks'];
  3300. }
  3301. }
  3302. /** ---------------------------------
  3303. /** Set "mode" cookie
  3304. /** ---------------------------------*/
  3305. // We do it now so we can destry it from the POST array
  3306. if (isset($_POST['mode']))
  3307. {
  3308. $FNS->set_cookie('mode' , $_POST['mode'], 60*60*24*182);
  3309. unset($_POST['mode']);
  3310. }
  3311. if ($cp_call == TRUE)
  3312. {
  3313. $allow_comments = ($IN->GBL('allow_comments', 'POST') == 'y') ? 'y' : 'n';
  3314. $allow_trackbacks = ($IN->GBL('allow_trackbacks', 'POST') == 'y') ? 'y' : 'n';
  3315. }
  3316. else
  3317. {
  3318. $allow_comments = ($IN->GBL('allow_comments', 'POST') !== 'y' || $comment_system_enabled == 'n') ? 'n' : 'y';
  3319. $allow_trackbacks = ($IN->GBL('allow_trackbacks', 'POST') !== 'y' || $trackback_system_enabled == 'n') ? 'n' : 'y';
  3320. }
  3321. /** --------------------------------------
  3322. /** Do we have a relationship?
  3323. /** --------------------------------------*/
  3324. // If the entry being submitted is the "parent" entry we need to compile and cache the "child" entry.
  3325. $query = $DB->query("SELECT field_id, field_related_to, field_related_id FROM exp_weblog_fields WHERE field_type = 'rel'");
  3326. $rel_updates = array();
  3327. if ($query->num_rows > 0)
  3328. {
  3329. foreach ($query->result as $row)
  3330. {
  3331. if (isset($_POST['field_id_'.$row['field_id']]))
  3332. {
  3333. $_POST['field_ft_'.$row['field_id']] = 'none';
  3334. $rel_exists = FALSE;
  3335. // If editing an existing entry....
  3336. // Does an existing relationship exist? If so, we may not need to recompile the data
  3337. if ($entry_id != '')
  3338. {
  3339. // First we fetch the previously stored related entry ID.
  3340. $rel_query = $DB->query("SELECT field_id_".$row['field_id']." FROM exp_weblog_data WHERE entry_id = '".$entry_id."'");
  3341. // If the previous ID matches the current ID being submitted it means that
  3342. // the existing relationship has not changed so there's no need to recompile.
  3343. // If it has changed we'll clear the old relationship.
  3344. if (is_numeric($rel_query->row['field_id_'.$row['field_id']]))
  3345. {
  3346. if ($rel_query->row['field_id_'.$row['field_id']] == $_POST['field_id_'.$row['field_id']])
  3347. {
  3348. $rel_exists = TRUE;
  3349. }
  3350. else
  3351. {
  3352. $DB->query("DELETE FROM exp_relationships WHERE rel_id = '".$rel_query->row['field_id_'.$row['field_id']]."'");
  3353. }
  3354. }
  3355. }
  3356. if (is_numeric($_POST['field_id_'.$row['field_id']]) AND $rel_exists == FALSE)
  3357. {
  3358. $reldata = array(
  3359. 'type' => $row['field_related_to'],
  3360. 'parent_id' => $entry_id,
  3361. 'child_id' => $_POST['field_id_'.$row['field_id']],
  3362. 'related_id' => $weblog_id
  3363. );
  3364. $_POST['field_id_'.$row['field_id']] = $FNS->compile_relationship($reldata, TRUE);
  3365. $rel_updates[] = $_POST['field_id_'.$row['field_id']];
  3366. }
  3367. }
  3368. }
  3369. }
  3370. /** ---------------------------------
  3371. /** Build our query data
  3372. /** ---------------------------------*/
  3373. if ($enable_versioning == 'n')
  3374. {
  3375. $version_enabled = 'y';
  3376. }
  3377. else
  3378. {
  3379. $version_enabled = (isset($_POST['versioning_enabled'])) ? 'y' : 'n';
  3380. }
  3381. $data = array(
  3382. 'entry_id' => '',
  3383. 'weblog_id' => $weblog_id,
  3384. 'author_id' => $author_id,
  3385. 'site_id' => $PREFS->ini('site_id'),
  3386. 'ip_address' => $IN->IP,
  3387. 'title' => ($PREFS->ini('auto_convert_high_ascii') == 'y') ? $REGX->ascii_to_entities($title) : $title,
  3388. 'url_title' => $url_title,
  3389. 'entry_date' => $entry_date,
  3390. 'edit_date' => date("YmdHis"),
  3391. 'versioning_enabled' => $version_enabled,
  3392. 'year' => date('Y', $entry_date),
  3393. 'month' => date('m', $entry_date),
  3394. 'day' => date('d', $entry_date),
  3395. 'expiration_date' => $expiration_date,
  3396. 'comment_expiration_date' => $comment_expiration_date,
  3397. 'sticky' => ($IN->GBL('sticky', 'POST') == 'y') ? 'y' : 'n',
  3398. 'status' => $status,
  3399. 'allow_comments' => $allow_comments,
  3400. 'allow_trackbacks' => $allow_trackbacks,
  3401. 'forum_topic_id' => ($IN->GBL('forum_topic_id') != '' AND is_numeric($IN->GBL('forum_topic_id'))) ? trim($IN->GBL('forum_topic_id')) : 0
  3402. );
  3403. // If we have the "honor_entry_dst" pref turned on we need to reverse the effects.
  3404. if ($PREFS->ini('honor_entry_dst') == 'y')
  3405. {
  3406. $data['dst_enabled'] = ($IN->GBL('dst_enabled', 'POST') == 'y') ? 'y' : 'n';
  3407. }
  3408. /** ---------------------------------
  3409. /** Insert the entry
  3410. /** ---------------------------------*/
  3411. if ($entry_id == '')
  3412. {
  3413. $DB->query($DB->insert_string('exp_weblog_titles', $data));
  3414. $entry_id = $DB->insert_id;
  3415. /** ------------------------------------
  3416. /** Update Relationships
  3417. /** ------------------------------------*/
  3418. if (sizeof($rel_updates) > 0)
  3419. {
  3420. $DB->query("UPDATE exp_relationships SET rel_parent_id = '".$entry_id."' WHERE rel_id IN (".implode(',', $rel_updates).")");
  3421. }
  3422. /** ------------------------------------
  3423. /** Insert the custom field data
  3424. /** ------------------------------------*/
  3425. $cust_fields = array('entry_id' => $entry_id, 'weblog_id' => $weblog_id);
  3426. foreach ($_POST as $key => $val)
  3427. {
  3428. if (strstr($key, 'field_offset_'))
  3429. {
  3430. unset($_POST[$key]);
  3431. continue;
  3432. }
  3433. if (strstr($key, 'field'))
  3434. {
  3435. if ($key == 'field_ft_'.$trackback_field)
  3436. {
  3437. $tb_format = $val;
  3438. }
  3439. if (strstr($key, 'field_id_') AND ! is_numeric($val))
  3440. {
  3441. $cust_fields[$key] = ($PREFS->ini('auto_convert_high_ascii') == 'y') ? $REGX->ascii_to_entities($val) : $val;
  3442. }
  3443. else
  3444. {
  3445. $cust_fields[$key] = $val;
  3446. }
  3447. }
  3448. }
  3449. if (count($cust_fields) > 0)
  3450. {
  3451. $cust_fields['site_id'] = $PREFS->ini('site_id');
  3452. // Submit the custom fields
  3453. $DB->query($DB->insert_string('exp_weblog_data', $cust_fields));
  3454. }
  3455. /** ------------------------------------
  3456. /** Update member stats
  3457. /** ------------------------------------*/
  3458. if ($data['author_id'] == $SESS->userdata('member_id'))
  3459. {
  3460. $total_entries = $SESS->userdata['total_entries'] +1;
  3461. }
  3462. else
  3463. {
  3464. $query = $DB->query("SELECT total_entries FROM exp_members WHERE member_id = '".$data['author_id']."'");
  3465. $total_entries = $query->row['total_entries'] + 1;
  3466. }
  3467. $DB->query("UPDATE exp_members set total_entries = '$total_entries', last_entry_date = '".$LOC->now."' WHERE member_id = '".$data['author_id']."'");
  3468. /** -------------------------------------
  3469. /** Set page title and success message
  3470. /** -------------------------------------*/
  3471. $type = 'new';
  3472. $page_title = 'entry_has_been_added';
  3473. $message = $LANG->line($page_title);
  3474. /** -------------------------------------
  3475. /** Is there a forum post?
  3476. /** -------------------------------------*/
  3477. if ($PREFS->ini('forum_is_installed') == "y" AND $IN->GBL('forum_title') != '' AND $IN->GBL('forum_body') != '')
  3478. {
  3479. $query = $DB->query("SELECT board_id FROM exp_forums WHERE forum_id = '".$DB->escape_str($IN->GBL('forum_id'))."'");
  3480. if ($query->num_rows > 0)
  3481. {
  3482. $title = $this->_convert_forum_tags($IN->GBL('forum_title'));
  3483. $body = $this->_convert_forum_tags(str_replace('{permalink}',
  3484. $FNS->remove_double_slashes($comment_url.'/'.$url_title.'/'),
  3485. $IN->GBL('forum_body')));
  3486. $DB->query($DB->insert_string('exp_forum_topics',
  3487. array(
  3488. 'topic_id' => '',
  3489. 'forum_id' => $IN->GBL('forum_id'),
  3490. 'board_id' => $query->row['board_id'],
  3491. 'topic_date' => $LOC->now,
  3492. 'title' => $REGX->xss_clean($title),
  3493. 'body' => $REGX->xss_clean($body),
  3494. 'author_id' => $author_id,
  3495. 'ip_address' => $IN->IP,
  3496. 'last_post_date' => $LOC->now,
  3497. 'last_post_author_id' => $author_id,
  3498. 'sticky' => 'n',
  3499. 'status' => 'o',
  3500. 'announcement' => 'n',
  3501. 'poll' => 'n',
  3502. 'parse_smileys' => 'y',
  3503. 'thread_total' => 1
  3504. )
  3505. )
  3506. );
  3507. $topic_id = $DB->insert_id;
  3508. $rand = $author_id.$FNS->random('alpha', 8);
  3509. $DB->query("UPDATE exp_weblog_titles SET forum_topic_id = '{$topic_id}' WHERE entry_id = '{$entry_id}'");
  3510. $DB->query("INSERT INTO exp_forum_subscriptions (topic_id, member_id, subscription_date, hash)
  3511. VALUES
  3512. ('{$topic_id}', '{$author_id}', '{$LOC->now}', '{$rand}')");
  3513. // Update the forum stats
  3514. if ( ! class_exists('Forum'))
  3515. {
  3516. require PATH_MOD.'forum/mod.forum'.EXT;
  3517. require PATH_MOD.'forum/mod.forum_core'.EXT;
  3518. }
  3519. Forum_Core::_update_post_stats($IN->GBL('forum_id'));
  3520. // Update member post total
  3521. $DB->query("UPDATE exp_members SET last_forum_post_date = '{$LOC->now}' WHERE member_id = '".$author_id."'");
  3522. }
  3523. }
  3524. /** ----------------------------
  3525. /** Send admin notification
  3526. /** ----------------------------*/
  3527. if ($notify_address != '')
  3528. {
  3529. $swap = array(
  3530. 'name' => $SESS->userdata('screen_name'),
  3531. 'email' => $SESS->userdata('email'),
  3532. 'weblog_name' => $blog_title,
  3533. 'entry_title' => $title,
  3534. 'entry_url' => $FNS->remove_double_slashes($blog_url.'/'.$url_title.'/'),
  3535. 'comment_url' => $FNS->remove_double_slashes($comment_url.'/'.$url_title.'/')
  3536. );
  3537. $template = $FNS->fetch_email_template('admin_notify_entry');
  3538. $email_tit = $FNS->var_swap($template['title'], $swap);
  3539. $email_msg = $FNS->var_swap($template['data'], $swap);
  3540. // We don't want to send a notification if the person
  3541. // leaving the entry is in the notification list
  3542. if (stristr($notify_address, $SESS->userdata['email']))
  3543. {
  3544. $notify_address = str_replace($SESS->userdata('email'), "", $notify_address);
  3545. }
  3546. $notify_address = $REGX->remove_extra_commas($notify_address);
  3547. if ($notify_address != '')
  3548. {
  3549. /** ----------------------------
  3550. /** Send email
  3551. /** ----------------------------*/
  3552. if ( ! class_exists('EEmail'))
  3553. {
  3554. require PATH_CORE.'core.email'.EXT;
  3555. }
  3556. $email = new EEmail;
  3557. foreach (explode(',', $notify_address) as $addy)
  3558. {
  3559. $email->initialize();
  3560. $email->wordwrap = false;
  3561. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  3562. $email->to($addy);
  3563. $email->reply_to($PREFS->ini('webmaster_email'));
  3564. $email->subject($email_tit);
  3565. $email->message($REGX->entities_to_ascii($email_msg));
  3566. $email->Send();
  3567. }
  3568. }
  3569. }
  3570. }
  3571. else
  3572. {
  3573. /** ---------------------------------
  3574. /** Update an existing entry
  3575. /** ---------------------------------*/
  3576. if ($PREFS->ini('honor_entry_dst') == 'y')
  3577. {
  3578. $data['entry_date'] = $LOC->offset_entry_dst($data['entry_date'], $data['dst_enabled']);
  3579. if ($data['expiration_date'] != '' AND $data['expiration_date'] != 0)
  3580. $data['expiration_date'] = $LOC->offset_entry_dst($data['expiration_date'], $data['dst_enabled']);
  3581. if ($data['comment_expiration_date'] != '' AND $data['comment_expiration_date'] != 0)
  3582. $data['comment_expiration_date'] = $LOC->offset_entry_dst($data['comment_expiration_date'], $data['dst_enabled']);
  3583. }
  3584. // First we need to see if the author of the entry has changed.
  3585. $query = $DB->query("SELECT author_id FROM exp_weblog_titles WHERE entry_id = '$entry_id'");
  3586. $old_author = $query->row['author_id'];
  3587. if ($old_author != $data['author_id'])
  3588. {
  3589. // Decremenet the counter on the old author
  3590. $query = $DB->query("SELECT total_entries FROM exp_members WHERE member_id = '$old_author'");
  3591. $total_entries = $query->row['total_entries'] - 1;
  3592. $DB->query("UPDATE exp_members set total_entries = '$total_entries' WHERE member_id = '$old_author'");
  3593. // Increment the counter on the new author
  3594. $query = $DB->query("SELECT total_entries FROM exp_members WHERE member_id = '".$data['author_id']."'");
  3595. $total_entries = $query->row['total_entries'] + 1;
  3596. $DB->query("UPDATE exp_members set total_entries = '$total_entries' WHERE member_id = '".$data['author_id']."'");
  3597. }
  3598. /** ------------------------------------
  3599. /** Update the entry
  3600. /** ------------------------------------*/
  3601. unset($data['entry_id']);
  3602. $topic_id = $data['forum_topic_id'];
  3603. $DB->query($DB->update_string('exp_weblog_titles', $data, "entry_id = '$entry_id'"));
  3604. /** ------------------------------------
  3605. /** Update the custom fields
  3606. /** ------------------------------------*/
  3607. $cust_fields = array('weblog_id' => $weblog_id);
  3608. foreach ($_POST as $key => $val)
  3609. {
  3610. if (strstr($key, 'field_offset_'))
  3611. {
  3612. // removed the unset in 1.6.5 as the localization was being lost on quicksave
  3613. // unset($_POST[$key]);
  3614. continue;
  3615. }
  3616. if (strstr($key, 'field'))
  3617. {
  3618. if ($key == 'field_ft_'.$trackback_field)
  3619. {
  3620. $tb_format = $val;
  3621. }
  3622. if (strstr($key, 'field_id_') AND ! is_numeric($val))
  3623. {
  3624. $cust_fields[$key] = ($PREFS->ini('auto_convert_high_ascii') == 'y') ? $REGX->ascii_to_entities($val) : $val;
  3625. }
  3626. else
  3627. {
  3628. $cust_fields[$key] = $val;
  3629. }
  3630. }
  3631. }
  3632. if (count($cust_fields) > 0)
  3633. {
  3634. // Update the custom fields
  3635. $DB->query($DB->update_string('exp_weblog_data', $cust_fields, "entry_id = '$entry_id'"));
  3636. }
  3637. /** ------------------------------------
  3638. /** Delete categories
  3639. /** ------------------------------------*/
  3640. // We will resubmit all categories next
  3641. $DB->query("DELETE FROM exp_category_posts WHERE entry_id = '$entry_id'");
  3642. /** ------------------------------------
  3643. /** Set page title and success message
  3644. /** ------------------------------------*/
  3645. $type = 'update';
  3646. $page_title = 'entry_has_been_updated';
  3647. $message = $LANG->line($page_title);
  3648. }
  3649. /** ---------------------------------
  3650. /** Insert categories
  3651. /** ---------------------------------*/
  3652. if ($this->cat_parents > 0)
  3653. {
  3654. $this->cat_parents = array_unique($this->cat_parents);
  3655. sort($this->cat_parents);
  3656. foreach($this->cat_parents as $val)
  3657. {
  3658. if ($val != '')
  3659. {
  3660. $DB->query("INSERT INTO exp_category_posts (entry_id, cat_id) VALUES ('$entry_id', '$val')");
  3661. }
  3662. }
  3663. }
  3664. /** --------------------------------------
  3665. /** Is this entry a child of another parent?
  3666. /** --------------------------------------*/
  3667. // If the entry being submitted is a "child" of another parent
  3668. // we need to re-compile and cache the data. Confused? Me too...
  3669. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_relationships WHERE rel_type = 'blog' AND rel_child_id = '".$DB->escape_str($entry_id)."'");
  3670. if ($query->row['count'] > 0)
  3671. {
  3672. $reldata = array(
  3673. 'type' => 'blog',
  3674. 'child_id' => $entry_id
  3675. );
  3676. $FNS->compile_relationship($reldata, FALSE);
  3677. }
  3678. /** --------------------------------------
  3679. /** Is this entry a parent of a child?
  3680. /** --------------------------------------*/
  3681. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_relationships
  3682. WHERE rel_parent_id = '".$DB->escape_str($entry_id)."'
  3683. AND reverse_rel_data != ''");
  3684. if ($query->row['count'] > 0)
  3685. {
  3686. $reldata = array(
  3687. 'type' => 'blog',
  3688. 'parent_id' => $entry_id
  3689. );
  3690. $FNS->compile_relationship($reldata, FALSE, TRUE);
  3691. }
  3692. /** -------------------------------------
  3693. /** Is there a forum post to update
  3694. /** -------------------------------------*/
  3695. if ($PREFS->ini('forum_is_installed') == "y" AND $IN->GBL('forum_title') != '' AND $IN->GBL('forum_body') != '' AND $topic_id != 0)
  3696. {
  3697. $title = $this->_convert_forum_tags($IN->GBL('forum_title'));
  3698. $body = $this->_convert_forum_tags(str_replace('{permalink}',
  3699. $FNS->remove_double_slashes($comment_url.'/'.$url_title.'/'),
  3700. $IN->GBL('forum_body')));
  3701. $DB->query("UPDATE exp_forum_topics SET title = '{$title}', body = '{$body}' WHERE topic_id = '{$topic_id}' ");
  3702. // Update the forum stats
  3703. if ( ! class_exists('Forum'))
  3704. {
  3705. require PATH_MOD.'forum/mod.forum'.EXT;
  3706. require PATH_MOD.'forum/mod.forum_core'.EXT;
  3707. }
  3708. Forum_Core::_update_post_stats($IN->GBL('forum_id'));
  3709. }
  3710. /** -------------------------------------
  3711. /** Is there a Page being updated or created?
  3712. /** -------------------------------------*/
  3713. if ($PREFS->ini('site_pages') !== FALSE &&
  3714. $IN->GBL('pages_uri', 'POST') !== FALSE && $IN->GBL('pages_uri', 'POST') != '' && $IN->GBL('pages_uri', 'POST') != '/example/pages/uri/' &&
  3715. is_numeric($IN->GBL('pages_template_id', 'POST')))
  3716. {
  3717. /** ----------------------------------------
  3718. /** Update the Very, Most Current Pages Data for Site
  3719. /** ----------------------------------------*/
  3720. $static_pages['uris'][$entry_id] = '/'.trim(preg_replace("#[^a-zA-Z0-9_\-/\.]+$#i", '', str_replace($PREFS->ini('site_url'), '', $IN->GBL('pages_uri'))), '/').'/';
  3721. $static_pages['templates'][$entry_id] = preg_replace("#[^0-9]+$#i", '', $IN->GBL('pages_template_id', 'POST'));
  3722. if ($static_pages['uris'][$entry_id] == '//')
  3723. {
  3724. $static_pages['uris'][$entry_id] = '/';
  3725. }
  3726. $DB->query($DB->update_string('exp_sites',
  3727. array('site_pages' => addslashes(serialize($static_pages))),
  3728. "site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'"));
  3729. }
  3730. /** ----------------------------------------
  3731. /** Save revisions if needed
  3732. /** ----------------------------------------*/
  3733. if ( ! isset($_POST['versioning_enabled']))
  3734. {
  3735. $enable_versioning = 'n';
  3736. }
  3737. if (isset($_POST['save']) AND $enable_qucksave_versioning == 'n')
  3738. {
  3739. $enable_versioning = 'n';
  3740. }
  3741. if ($enable_versioning == 'y')
  3742. {
  3743. $DB->query("INSERT INTO exp_entry_versioning (version_id, entry_id, weblog_id, author_id, version_date, version_data) VALUES ('', '".$entry_id."', '".$weblog_id."', '".$SESS->userdata('member_id')."', '".$LOC->now."', '".addslashes(serialize($revision_post))."')");
  3744. // Clear old revisions if needed
  3745. $max = (is_numeric($max_revisions) AND $max_revisions > 0) ? $max_revisions : 10;
  3746. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_entry_versioning WHERE entry_id = '".$entry_id."'");
  3747. if ($query->row['count'] > $max)
  3748. {
  3749. $query = $DB->query("SELECT version_id FROM exp_entry_versioning WHERE entry_id = '".$entry_id."' ORDER BY version_id desc limit ".$max);
  3750. $ids = '';
  3751. foreach ($query->result as $row)
  3752. {
  3753. $ids .= $row['version_id'].',';
  3754. }
  3755. $ids = substr($ids, 0, -1);
  3756. $DB->query("DELETE FROM exp_entry_versioning WHERE version_id NOT IN (".$ids.") AND entry_id = '".$entry_id."'");
  3757. }
  3758. }
  3759. //---------------------------------
  3760. // Quick Save Returns Here
  3761. // - does not process pings
  3762. // - does not update stats
  3763. // - does not empty caches
  3764. //---------------------------------
  3765. if (isset($_POST['save']))
  3766. {
  3767. return $this->new_entry_form('save', '', $entry_id);
  3768. }
  3769. /** ----------------------------------------
  3770. /** Update global stats
  3771. /** ----------------------------------------*/
  3772. $STAT->update_weblog_stats($weblog_id);
  3773. if ($old_weblog != '')
  3774. {
  3775. $STAT->update_weblog_stats($old_weblog);
  3776. }
  3777. /** ---------------------------------
  3778. /** Send trackbacks
  3779. /** ---------------------------------*/
  3780. $tb_body = ( ! isset($_POST['field_id_'.$trackback_field])) ? '' : $_POST['field_id_'.$trackback_field];
  3781. if ($trackback_urls != '' AND $tb_body != '' AND $data['status'] != 'closed' AND $data['entry_date'] < ($LOC->now + 90))
  3782. {
  3783. $entry_link = $REGX->prep_query_string($tb_url);
  3784. $entry_link = $FNS->remove_double_slashes($entry_link.'/'.$url_title.'/');
  3785. $tb_data = array( 'entry_id' => $entry_id,
  3786. 'entry_link' => $FNS->remove_double_slashes($entry_link),
  3787. 'entry_title' => $title,
  3788. 'entry_content' => $tb_body,
  3789. 'tb_format' => $tb_format,
  3790. 'weblog_name' => $blog_title,
  3791. 'trackback_url' => $trackback_urls
  3792. );
  3793. require PATH_MOD.'trackback/mcp.trackback'.EXT;
  3794. $TB = new Trackback_CP;
  3795. $tb_res = $TB->send_trackback($tb_data);
  3796. /** ---------------------------------------
  3797. /** Update the "sent_trackbacks" field
  3798. /** ---------------------------------------*/
  3799. // Fetch the URLs that were sent successfully and update the DB
  3800. if (count($tb_res['0']) > 0)
  3801. {
  3802. foreach ($tb_res['0'] as $val)
  3803. {
  3804. $sent_trackbacks .= $val."\n";
  3805. }
  3806. $DB->query("UPDATE exp_weblog_titles SET sent_trackbacks = '$sent_trackbacks' WHERE entry_id = '$entry_id'");
  3807. }
  3808. if (count($tb_res['1']) > 0)
  3809. {
  3810. $tb_errors = TRUE;
  3811. }
  3812. }
  3813. /** ---------------------------------
  3814. /** Send xml-rpc pings
  3815. /** ---------------------------------*/
  3816. $ping_message = '';
  3817. if (count($ping_servers) > 0)
  3818. {
  3819. // We only ping entries that are posted now, not in the future
  3820. if (($entry_date-90) < $LOC->now)
  3821. {
  3822. $ping_result = $this->send_pings($ping_servers, $blog_title, $ping_url, $rss_url);
  3823. if (is_array($ping_result) AND count($ping_result) > 0)
  3824. {
  3825. $ping_errors = TRUE;
  3826. $ping_message .= $DSP->qdiv('highlight', $DSP->qdiv('defaultBold', $LANG->line('xmlrpc_ping_errors')));
  3827. foreach ($ping_result as $val)
  3828. {
  3829. $ping_message .= $DSP->qdiv('highlight', $DSP->qspan('highlight_bold', $val['0']).' - '.$val['1']);
  3830. }
  3831. }
  3832. }
  3833. /** ---------------------------------
  3834. /** Save ping button state
  3835. /** ---------------------------------*/
  3836. $DB->query("DELETE FROM exp_entry_ping_status WHERE entry_id = '$entry_id'");
  3837. foreach ($ping_servers as $val)
  3838. {
  3839. $DB->query("INSERT INTO exp_entry_ping_status (entry_id, ping_id) VALUES ('$entry_id', '$val')");
  3840. }
  3841. }
  3842. /** ---------------------------------
  3843. /** Clear caches if needed
  3844. /** ---------------------------------*/
  3845. if ($PREFS->ini('new_posts_clear_caches') == 'y')
  3846. {
  3847. $FNS->clear_caching('all');
  3848. }
  3849. else
  3850. {
  3851. $FNS->clear_caching('sql');
  3852. }
  3853. // -------------------------------------------
  3854. // 'submit_new_entry_end' hook.
  3855. // - Add More Stuff to Do For Entry
  3856. // - 1.5.2 => Added $ping_message variable
  3857. //
  3858. $edata = $EXT->call_extension('submit_new_entry_end', $entry_id, $data, $ping_message);
  3859. if ($EXT->end_script === TRUE) return;
  3860. //
  3861. // -------------------------------------------
  3862. /** ---------------------------------------
  3863. /** Show ping erors if there are any
  3864. /** ---------------------------------------*/
  3865. if ($tb_errors == TRUE || $ping_errors == TRUE)
  3866. {
  3867. if ($cp_call == TRUE)
  3868. {
  3869. $r = $DSP->qdiv('success', $LANG->line($page_title).BR.BR);
  3870. if (isset($tb_res['1']) AND count($tb_res['1']) > 0)
  3871. {
  3872. $r .= $DSP->qdiv('highlight', $DSP->qdiv('defaultBold', $LANG->line('trackback_url_errors')));
  3873. foreach ($tb_res['1'] as $val)
  3874. {
  3875. $r .= $DSP->qdiv('highlight', $DSP->qspan('highlight_bold', $val['0']).' - '.$val['1']);
  3876. }
  3877. }
  3878. $r .= $ping_message;
  3879. $r .= $DSP->qdiv('', BR.$DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$IN->GBL('weblog_id', 'POST').AMP.'entry_id='.$entry_id, $LANG->line('click_to_view_your_entry')));
  3880. return $DSP->set_return_data($LANG->line('publish'),$r);
  3881. }
  3882. }
  3883. /** ---------------------------------
  3884. /** Redirect to ths "success" page
  3885. /** ---------------------------------*/
  3886. if ($cp_call == TRUE)
  3887. {
  3888. $loc = BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id.AMP.'U='.$type;
  3889. }
  3890. else
  3891. {
  3892. $FNS->template_type = 'webpage';
  3893. $loc = ($return_url == '') ? $FNS->fetch_site_index() : $FNS->create_url($return_url, 1, 1);
  3894. }
  3895. // -------------------------------------------
  3896. // 'submit_new_entry_redirect' hook.
  3897. // - Modify Redirect Location
  3898. // - 1.5.2 => Added $cp_call variable
  3899. //
  3900. if ($EXT->active_hook('submit_new_entry_redirect') === TRUE)
  3901. {
  3902. $loc = $EXT->call_extension('submit_new_entry_redirect', $entry_id, $data, $cp_call);
  3903. if ($EXT->end_script === TRUE) return;
  3904. }
  3905. //
  3906. // -------------------------------------------
  3907. // -------------------------------------------
  3908. // 'submit_new_entry_absolute_end' hook.
  3909. // - Add More Stuff to Do For Entry
  3910. // - Still allows Trackback/Ping error messages
  3911. //
  3912. $edata = $EXT->call_extension('submit_new_entry_absolute_end', $entry_id, $data);
  3913. if ($EXT->end_script === TRUE) return;
  3914. //
  3915. // -------------------------------------------
  3916. $FNS->redirect($loc);
  3917. exit;
  3918. }
  3919. /* END */
  3920. /** ---------------------------------
  3921. /** Send Pings
  3922. /** ---------------------------------*/
  3923. function send_pings($ping_servers, $blog_title, $ping_url, $rss_url)
  3924. {
  3925. global $DB, $PREFS;
  3926. $sql = "SELECT server_name, server_url, port FROM exp_ping_servers WHERE id IN (";
  3927. foreach ($ping_servers as $id)
  3928. {
  3929. $sql .= "'$id',";
  3930. }
  3931. $sql = substr($sql, 0, -1).') ';
  3932. $query = $DB->query($sql);
  3933. if ($query->num_rows == 0)
  3934. {
  3935. return FALSE;
  3936. }
  3937. if ( ! class_exists('XML_RPC'))
  3938. {
  3939. require PATH_CORE.'core.xmlrpc'.EXT;
  3940. }
  3941. $XRPC = new XML_RPC;
  3942. $result = array();
  3943. foreach ($query->result as $row)
  3944. {
  3945. if (($response = $XRPC->weblogs_com_ping($row['server_url'], $row['port'], $blog_title, $ping_url, $rss_url)) !== TRUE)
  3946. {
  3947. $result[] = array($row['server_name'], $response);
  3948. }
  3949. }
  3950. return $result;
  3951. }
  3952. /* END */
  3953. /** ----------------------------------------
  3954. /** Convert forum special characters
  3955. /** ----------------------------------------*/
  3956. function _convert_forum_tags($str)
  3957. {
  3958. $str = str_replace('{include:', '&#123;include:', $str);
  3959. $str = str_replace('{path:', '&#123;path:', $str);
  3960. $str = str_replace('{lang:', '&#123;lang:', $str);
  3961. return $str;
  3962. }
  3963. /* END */
  3964. /** --------------------------------------------
  3965. /** Category tree
  3966. /** --------------------------------------------*/
  3967. // This function (and the next) create a higherarchy tree
  3968. // of categories. There are two versions of the tree. The
  3969. // "text" version is a list of links allowing the categories
  3970. // to be edited. The "form" version is displayed in a
  3971. // multi-select form on the new entry page.
  3972. //--------------------------------------------
  3973. function category_tree($group_id = '', $action = '', $default = '', $selected = '')
  3974. {
  3975. global $DSP, $IN, $REGX, $DB;
  3976. // Fetch category group ID number
  3977. if ($group_id == '')
  3978. {
  3979. if ( ! $group_id = $IN->GBL('group_id'))
  3980. return false;
  3981. }
  3982. // If we are using the category list on the "new entry" page
  3983. // and the person is returning to the edit page after previewing,
  3984. // we need to gather the selected categories so we can highlight
  3985. // them in the form.
  3986. if ($action == 'preview' OR $action == 'save')
  3987. {
  3988. $catarray = array();
  3989. foreach ($_POST as $key => $val)
  3990. {
  3991. if (strstr($key, 'category'))
  3992. {
  3993. $catarray[$val] = $val;
  3994. }
  3995. }
  3996. }
  3997. if ($action == 'edit')
  3998. {
  3999. $catarray = array();
  4000. if (is_array($selected))
  4001. {
  4002. foreach ($selected as $key => $val)
  4003. {
  4004. $catarray[$val] = $val;
  4005. }
  4006. }
  4007. }
  4008. // Fetch category groups
  4009. if ( ! is_numeric(str_replace('|', "", $group_id)))
  4010. {
  4011. return FALSE;
  4012. }
  4013. $query = $DB->query("SELECT cat_name, cat_id, parent_id, group_id
  4014. FROM exp_categories
  4015. WHERE group_id IN ('".str_replace('|', "','", $DB->escape_str($group_id))."')
  4016. ORDER BY group_id, parent_id, cat_order");
  4017. if ($query->num_rows == 0)
  4018. {
  4019. return false;
  4020. }
  4021. // Assign the query result to a multi-dimensional array
  4022. foreach($query->result as $row)
  4023. {
  4024. $cat_array[$row['cat_id']] = array($row['parent_id'], $row['cat_name'], $row['group_id']);
  4025. }
  4026. $size = count($cat_array) + 1;
  4027. $this->categories[] = $DSP->input_select_header('category[]', 1, $size);
  4028. // Build our output...
  4029. $sel = '';
  4030. foreach($cat_array as $key => $val)
  4031. {
  4032. if (0 == $val['0'])
  4033. {
  4034. if (isset($last_group) && $last_group != $val['2'])
  4035. {
  4036. $this->categories[] = $DSP->input_select_option('', '-------');
  4037. }
  4038. if ($action == 'new')
  4039. {
  4040. $sel = ($default == $key) ? '1' : '';
  4041. }
  4042. else
  4043. {
  4044. $sel = (isset($catarray[$key])) ? '1' : '';
  4045. }
  4046. $this->categories[] = $DSP->input_select_option($key, $val['1'], $sel);
  4047. $this->category_subtree($key, $cat_array, $depth=1, $action, $default, $selected);
  4048. $last_group = $val['2'];
  4049. }
  4050. }
  4051. $this->categories[] = $DSP->input_select_footer();
  4052. }
  4053. /* END */
  4054. /** --------------------------------------------
  4055. /** Category sub-tree
  4056. /** --------------------------------------------*/
  4057. // This function works with the preceeding one to show a
  4058. // hierarchical display of categories
  4059. //--------------------------------------------
  4060. function category_subtree($cat_id, $cat_array, $depth, $action, $default = '', $selected = '')
  4061. {
  4062. global $DSP, $IN, $DB, $REGX, $LANG;
  4063. $spcr = "&nbsp;";
  4064. // Just as in the function above, we'll figure out which items are selected.
  4065. if ($action == 'preview' OR $action == 'save')
  4066. {
  4067. $catarray = array();
  4068. foreach ($_POST as $key => $val)
  4069. {
  4070. if (strstr($key, 'category'))
  4071. {
  4072. $catarray[$val] = $val;
  4073. }
  4074. }
  4075. }
  4076. if ($action == 'edit')
  4077. {
  4078. $catarray = array();
  4079. if (is_array($selected))
  4080. {
  4081. foreach ($selected as $key => $val)
  4082. {
  4083. $catarray[$val] = $val;
  4084. }
  4085. }
  4086. }
  4087. $indent = $spcr.$spcr.$spcr.$spcr;
  4088. if ($depth == 1)
  4089. {
  4090. $depth = 4;
  4091. }
  4092. else
  4093. {
  4094. $indent = str_repeat($spcr, $depth).$indent;
  4095. $depth = $depth + 4;
  4096. }
  4097. $sel = '';
  4098. foreach ($cat_array as $key => $val)
  4099. {
  4100. if ($cat_id == $val['0'])
  4101. {
  4102. $pre = ($depth > 2) ? "&nbsp;" : '';
  4103. if ($action == 'new')
  4104. {
  4105. $sel = ($default == $key) ? '1' : '';
  4106. }
  4107. else
  4108. {
  4109. $sel = (isset($catarray[$key])) ? '1' : '';
  4110. }
  4111. $this->categories[] = $DSP->input_select_option($key, $pre.$indent.$spcr.$val['1'], $sel);
  4112. $this->category_subtree($key, $cat_array, $depth, $action, $default, $selected);
  4113. }
  4114. }
  4115. }
  4116. /* END */
  4117. /** ---------------------------------------------------------------
  4118. /** Text formatting buttons
  4119. /** ---------------------------------------------------------------*/
  4120. // This function displays radio buttons used to select
  4121. // between xhtml, auto <br /> and "none" on the new entry page
  4122. //---------------------------------------------------------------
  4123. function text_formatting_buttons($id, $default = 'xhtml')
  4124. {
  4125. global $DB, $DSP, $LANG;
  4126. $LANG->fetch_language_file('publish_ad');
  4127. if ($default == '')
  4128. $default = 'xhtml';
  4129. $query = $DB->query("SELECT field_fmt FROM exp_field_formatting WHERE field_id = '$id' AND field_fmt != 'none' ORDER BY field_fmt");
  4130. $spacer = NBS.NBS.NBS.NBS.'|'.NBS.NBS.NBS.NBS;
  4131. if ($this->SPELL->enabled === TRUE)
  4132. {
  4133. $spell_check = ' <a href="javascript:void(0);" onclick="showhide_spellcheck(\''.$id.'\');return false;"><b>'.
  4134. $LANG->line('check_spelling').'</b></a>'.$spacer;
  4135. }
  4136. else
  4137. {
  4138. $spell_check = '';
  4139. }
  4140. $glossary = ' <a href="javascript:void(0);" onclick="showhide_glossary(\''.$id.'\');return false;"><b>'.$LANG->line('html_glossary').'</b></a>'.$spacer;
  4141. $smileys = ' <a href="javascript:void(0);" onclick="showhide_smileys(\''.$id.'\');return false;"><b>'.$LANG->line('emoticons').'</b></a>'.$spacer;
  4142. $r = $DSP->div('xhtmlWrapper').$DSP->qspan('lightLinks', $spell_check.$glossary.$smileys).$DSP->qspan('xhtmlWrapperLight', $LANG->line('newline_format'));
  4143. $r .= $DSP->input_select_header('field_ft_'.$id);
  4144. if ($query->num_rows > 0)
  4145. {
  4146. foreach ($query->result as $row)
  4147. {
  4148. $name = ucwords(str_replace('_', ' ', $row['field_fmt']));
  4149. if ($name == 'Br')
  4150. {
  4151. $name = $LANG->line('auto_br');
  4152. }
  4153. elseif ($name == 'Xhtml')
  4154. {
  4155. $name = $LANG->line('xhtml');
  4156. }
  4157. $sel = ($default == $row['field_fmt']) ? 1 : 0;
  4158. $r .= $DSP->input_select_option($row['field_fmt'], $name, $sel);
  4159. }
  4160. }
  4161. $sel = ($default == 'none') ? 1 : 0;
  4162. $r .= $DSP->input_select_option('none', $LANG->line('none'), $sel);
  4163. $r .= $DSP->input_select_footer().NBS;
  4164. $r .= $DSP->div_c();
  4165. return $r;
  4166. }
  4167. /* END */
  4168. /** ---------------------------------------------------------------
  4169. /** Fetch ping servers
  4170. /** ---------------------------------------------------------------*/
  4171. // This function displays the ping server checkboxes
  4172. //---------------------------------------------------------------
  4173. function fetch_ping_servers($member_id = '', $entry_id = '', $which = 'new', $show = TRUE)
  4174. {
  4175. global $LANG, $DB, $SESS, $DSP, $PREFS;
  4176. $sent_pings = array();
  4177. if ($entry_id != '')
  4178. {
  4179. $query = $DB->query("SELECT ping_id FROM exp_entry_ping_status WHERE entry_id = '$entry_id'");
  4180. if ($query->num_rows > 0)
  4181. {
  4182. foreach ($query->result as $row)
  4183. {
  4184. $sent_pings[$row['ping_id']] = TRUE;
  4185. }
  4186. }
  4187. }
  4188. if ($member_id == '')
  4189. {
  4190. $member_id = $SESS->userdata('member_id');
  4191. }
  4192. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_ping_servers WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '".$SESS->userdata('member_id')."'");
  4193. $member_id = ($query->row['count'] == 0) ? 0 : $SESS->userdata('member_id');
  4194. $query = $DB->query("SELECT id, server_name, is_default FROM exp_ping_servers WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id' ORDER BY server_order");
  4195. if ($query->num_rows == 0)
  4196. {
  4197. return false;
  4198. }
  4199. $r = '';
  4200. ob_start();
  4201. ?>
  4202. <script type="text/javascript">
  4203. <!--
  4204. function toggle(thebutton)
  4205. {
  4206. var checkbox_list = document.getElementById('pingDiv').getElementsByTagName('input');
  4207. for (i=0; i<checkbox_list.length; i++) //for (var i in checkbox_list) feels more elegant... but IE... alas
  4208. {
  4209. checkbox_list[i].checked = (thebutton.checked) ? true : false;
  4210. }
  4211. }
  4212. //-->
  4213. </script>
  4214. <?php
  4215. $r .= ob_get_contents();
  4216. ob_end_clean();
  4217. $r .= '<div id="pingDiv" class="publishPad">';
  4218. foreach($query->result as $row)
  4219. {
  4220. if (isset($_POST['preview']))
  4221. {
  4222. $selected = '';
  4223. foreach ($_POST as $key => $val)
  4224. {
  4225. if (strstr($key, 'ping') AND $val == $row['id'])
  4226. {
  4227. $selected = 1;
  4228. break;
  4229. }
  4230. }
  4231. }
  4232. else
  4233. {
  4234. if ($entry_id != '')
  4235. {
  4236. $selected = (isset($sent_pings[$row['id']])) ? 1 : '';
  4237. }
  4238. else
  4239. {
  4240. $selected = ($row['is_default'] == 'y') ? 1 : '';
  4241. }
  4242. }
  4243. if ($which == 'edit')
  4244. {
  4245. $selected = '';
  4246. }
  4247. if ($show == TRUE)
  4248. {
  4249. $r .= $DSP->input_checkbox('ping[]', $row['id'], $selected).' '.$row['server_name'].'<br />';
  4250. }
  4251. else
  4252. {
  4253. if ($which != 'edit' AND $selected == 1)
  4254. {
  4255. $r .= $DSP->input_hidden('ping[]', $row['id']);
  4256. }
  4257. }
  4258. }
  4259. if ($show == TRUE)
  4260. {
  4261. $r .= $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").$DSP->qspan('highlight_alt', $LANG->line('select_all'));
  4262. }
  4263. $r .= '</div>';
  4264. return $r;
  4265. }
  4266. /* END */
  4267. /** ---------------------------------------------------------------
  4268. /** HTML formatting buttons
  4269. /** ---------------------------------------------------------------*/
  4270. // This function and the next display the HTML formatting buttons
  4271. //---------------------------------------------------------------
  4272. function default_buttons($close = TRUE, $allow_img_urls = 'y')
  4273. {
  4274. global $DSP, $LANG, $PREFS;
  4275. $buttons = array(
  4276. 'link' => array("javascript:promptTag(\"link\");", ''),
  4277. 'email' => array("javascript:promptTag(\"email\");", ''),
  4278. 'image' => array("javascript:promptTag(\"image\");", ''),
  4279. 'close_all' => array("javascript:closeall();", "")
  4280. );
  4281. /* -------------------------------------------
  4282. /* Hidden Configuration Variables
  4283. /* - remove_close_all_button => Remove the Close All button from the Publish/Edit page (y/n)
  4284. /* Useful because most browsers no longer need it and Admins might want it gone
  4285. /* -------------------------------------------*/
  4286. if ($close !== TRUE OR $PREFS->ini('remove_close_all_button') === 'y')
  4287. {
  4288. unset($buttons['close_all']);
  4289. }
  4290. if ($allow_img_urls != 'y')
  4291. {
  4292. unset($buttons['image']);
  4293. }
  4294. $r = '';
  4295. $i = 0;
  4296. foreach ($buttons as $k => $v)
  4297. {
  4298. if ($i == 0 AND $close == false)
  4299. {
  4300. $r .= $DSP->td('htmlButtonOuterL');
  4301. }
  4302. else
  4303. {
  4304. $r .= $DSP->td('htmlButtonOuter');
  4305. }
  4306. $i++;
  4307. $r .=
  4308. $DSP->div('htmlButtonInner').
  4309. $DSP->div('htmlButtonA', '', $k).
  4310. $DSP->anchor($v['0'], $LANG->line($k), $v['1']).
  4311. $DSP->div_c().
  4312. $DSP->div_c().
  4313. $DSP->td_c();
  4314. }
  4315. return $r;
  4316. }
  4317. /** ---------------------------------------------------------------
  4318. /** HTML formatting buttons
  4319. /** ---------------------------------------------------------------*/
  4320. // This function and the above display the HTML formatting buttons
  4321. //---------------------------------------------------------------
  4322. function html_formatting_buttons($member_id = '', $field_group, $extra_js = TRUE, $weblog_allow_img_urls = 'y')
  4323. {
  4324. global $DSP, $IN, $SESS, $DB, $LANG, $PREFS;
  4325. if ($member_id == '')
  4326. {
  4327. $member_id = $SESS->userdata('member_id');
  4328. }
  4329. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id'");
  4330. $member_id = ($query->row['count'] == 0) ? 0 : $SESS->userdata('member_id');
  4331. $query_one = $DB->query("SELECT * FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id' AND tag_row = '1' ORDER BY tag_order");
  4332. $query_two = $DB->query("SELECT * FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id' AND tag_row = '2' ORDER BY tag_order");
  4333. if ($query_one->num_rows == 0 AND $query_two->num_rows == 0)
  4334. {
  4335. return false;
  4336. }
  4337. $data = array();
  4338. if ($query_one->num_rows > 0)
  4339. {
  4340. $data[] = $query_one->result;
  4341. }
  4342. if ($query_two->num_rows > 0)
  4343. {
  4344. $data[] = $query_two->result;
  4345. }
  4346. $r = NL."<table border='0' cellpadding='0' cellspacing='0' style='width:99%;margin-bottom:3px;'><tr><td>";
  4347. $r .= $DSP->div('buttonInsert').
  4348. $DSP->div('itemWrapper');
  4349. if (count($data) > 0)
  4350. {
  4351. if ( ! $mode = $IN->GBL('mode', 'POST'))
  4352. {
  4353. if ( ! $mode = $IN->GBL('mode', 'COOKIE'))
  4354. {
  4355. $mode = '';
  4356. }
  4357. }
  4358. if ($mode == 'guided')
  4359. {
  4360. $guided = "checked='checked'";
  4361. $normal = "";
  4362. }
  4363. else
  4364. {
  4365. $normal = "checked='checked'";
  4366. $guided = "";
  4367. }
  4368. $r .= $DSP->div('smallLinks').'<b>'.$LANG->line('button_mode').'</b>'.$DSP->nbs(3).
  4369. $LANG->line('guided').NBS.
  4370. "<input type='radio' name='mode' value='guided' onclick='setmode(this.value)' $guided/>".
  4371. $DSP->nbs(2).
  4372. $LANG->line('normal').NBS.
  4373. "<input type='radio' name='mode' value='normal' onclick='setmode(this.value)' $normal/>".
  4374. $DSP->nbs(6);
  4375. }
  4376. $r .=
  4377. $DSP->div_c().
  4378. $DSP->div_c();
  4379. $jsvars = array();
  4380. if (count($data) == 0)
  4381. {
  4382. $r .= $DSP->table('buttonMargin', '0', '', '').
  4383. $DSP->tr().
  4384. $this->default_buttons(FALSE, $weblog_allow_img_urls).
  4385. $DSP->tr_c().
  4386. $DSP->table_c();
  4387. }
  4388. else
  4389. {
  4390. $rows = (count($data) == 1) ? 1 : 2;
  4391. $n = 0;
  4392. $i = 0;
  4393. foreach ($data as $groups)
  4394. {
  4395. $r .= $DSP->table('buttonMargin', '0', '', '').
  4396. $DSP->tr();
  4397. $edge = false;
  4398. foreach ($groups as $row)
  4399. {
  4400. $accesskey = ($row['accesskey'] != '') ? "accesskey=\"".trim($row['accesskey'])."\" " : "";
  4401. $jsfunc = $accesskey."onclick='taginsert(this, \"".htmlspecialchars(addslashes($row['tag_open']))."\", \"".htmlspecialchars(addslashes($row['tag_close']))."\")'";
  4402. $jsvars[] = 'button_'.$i;
  4403. if ($edge == false)
  4404. {
  4405. $r .= $DSP->td('htmlButtonOuterL');
  4406. }
  4407. else
  4408. {
  4409. $r .= $DSP->td('htmlButtonOuter');
  4410. $edge = true;
  4411. }
  4412. $r .= $DSP->div('htmlButtonInner').
  4413. "<div class='htmlButtonA' id='button_".$i."'>".
  4414. $DSP->anchor('javascript:nullo()', htmlspecialchars(trim($row['tag_name'])), " name='button_{$i}' $jsfunc").
  4415. $DSP->div_c().
  4416. $DSP->div_c().
  4417. $DSP->td_c();
  4418. $i++;
  4419. $edge = true;
  4420. }
  4421. if ($rows == 1 || ($rows == 2 AND $n == 0))
  4422. {
  4423. $r .= $this->default_buttons(TRUE, $weblog_allow_img_urls);
  4424. }
  4425. $r .=
  4426. $DSP->tr_c().
  4427. $DSP->table_c();
  4428. $n ++;
  4429. }
  4430. }
  4431. $r .= $DSP->div_c();
  4432. $r .= $DSP->td_c().
  4433. $DSP->tr_c().
  4434. $DSP->table_c();
  4435. ob_start();
  4436. ?>
  4437. <script type="text/javascript">
  4438. <!--
  4439. <?php
  4440. if ($extra_js !== FALSE)
  4441. {
  4442. ?>
  4443. /** ------------------------------------
  4444. /** Array Helper Functions
  4445. /** -------------------------------------*/
  4446. function getarraysize(thearray)
  4447. {
  4448. for (i = 0; i < thearray.length; i++)
  4449. {
  4450. if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
  4451. {
  4452. return i;
  4453. }
  4454. }
  4455. return thearray.length;
  4456. }
  4457. // Array push
  4458. function arraypush(thearray, value)
  4459. {
  4460. thearray[getarraysize(thearray)] = value;
  4461. }
  4462. // Array pop
  4463. function arraypop(thearray)
  4464. {
  4465. thearraysize = getarraysize(thearray);
  4466. retval = thearray[thearraysize - 1];
  4467. delete thearray[thearraysize - 1];
  4468. return retval;
  4469. }
  4470. <?php
  4471. }
  4472. ?>
  4473. var no_cursor = "<?php echo $LANG->line('html_buttons_no_cursor'); ?>";
  4474. var url_text = "<?php echo $LANG->line('html_buttons_url_text'); ?>";
  4475. var webpage_text = "<?php echo $LANG->line('html_buttons_webpage_text'); ?>";
  4476. var title_text = "<?php echo $LANG->line('html_buttons_title_text'); ?>";
  4477. var image_text = "<?php echo $LANG->line('html_buttons_image_text'); ?>";
  4478. var email_text = "<?php echo $LANG->line('html_buttons_email_text'); ?>";
  4479. var email_title = "<?php echo $LANG->line('html_buttons_email_title'); ?>";
  4480. var enter_text = "<?php echo $LANG->line('html_buttons_enter_text'); ?>";
  4481. <?php
  4482. echo "\n";
  4483. foreach ($jsvars as $val)
  4484. {
  4485. echo "var $val = 0;\n";
  4486. }
  4487. ?>
  4488. var tagarray = new Array();
  4489. var usedarray = new Array();
  4490. var running = 0;
  4491. function nullo()
  4492. {
  4493. return;
  4494. }
  4495. // State change
  4496. function styleswap(link)
  4497. {
  4498. if (document.getElementById(link).className == 'htmlButtonA')
  4499. {
  4500. document.getElementById(link).className = 'htmlButtonB';
  4501. }
  4502. else
  4503. {
  4504. document.getElementById(link).className = 'htmlButtonA';
  4505. }
  4506. if (document.getElementById('close_all').className == 'htmlButtonA')
  4507. {
  4508. document.getElementById('close_all').className = 'htmlButtonB';
  4509. }
  4510. }
  4511. // Set button mode
  4512. function setmode(which)
  4513. {
  4514. if (which == 'guided')
  4515. selMode = 'guided';
  4516. else
  4517. selMode = 'normal';
  4518. }
  4519. // Clear state
  4520. function clear_state()
  4521. {
  4522. if (usedarray[0])
  4523. {
  4524. while (usedarray[0])
  4525. {
  4526. clearState = arraypop(usedarray);
  4527. eval(clearState + " = 0");
  4528. document.getElementById(clearState).className = 'htmlButtonA';
  4529. }
  4530. if (document.getElementById('close_all').className == 'htmlButtonB')
  4531. {
  4532. document.getElementById('close_all').className = 'htmlButtonA';
  4533. }
  4534. }
  4535. }
  4536. // Prompted tags
  4537. function promptTag(which)
  4538. {
  4539. if ( ! selField)
  4540. {
  4541. alert(no_cursor);
  4542. return;
  4543. }
  4544. if ( ! which)
  4545. return;
  4546. var theSelection = "";
  4547. eval("var theField = document.getElementById('entryform')." + selField + ";");
  4548. if (document.selection)
  4549. {
  4550. if (document.selection.createRange().text)
  4551. {
  4552. theSelection = document.selection.createRange().text;
  4553. }
  4554. }
  4555. else if ( ! isNaN(theField.selectionEnd))
  4556. {
  4557. var selLength = theField.textLength;
  4558. var selStart = theField.selectionStart;
  4559. var selEnd = theField.selectionEnd;
  4560. if (selEnd <= 2 && typeof(selLength) != 'undefined')
  4561. selEnd = selLength;
  4562. var s1 = (theField.value).substring(0,selStart);
  4563. var s2 = (theField.value).substring(selStart, selEnd)
  4564. var s3 = (theField.value).substring(selEnd, selLength);
  4565. theSelection = s2;
  4566. }
  4567. if (which == "link")
  4568. {
  4569. var URL = prompt(url_text, "http://");
  4570. if ( ! URL || URL == 'http://' || URL == null)
  4571. return;
  4572. var Name = prompt(webpage_text, theSelection);
  4573. if (Name == null)
  4574. {
  4575. return;
  4576. }
  4577. if ( ! Name)
  4578. {
  4579. Name = URL;
  4580. }
  4581. var Title = prompt(title_text, theSelection);
  4582. if (Title == null)
  4583. return;
  4584. if (Title == "")
  4585. {
  4586. var Title = Name;
  4587. }
  4588. Title = Title.replace(/\"/g, '&quot;');
  4589. var Link = '<a href="' + URL + '" title="' + Title + '">' + Name + '<'+'/a>';
  4590. }
  4591. if (which == "email")
  4592. {
  4593. var Email = prompt(email_text, "");
  4594. if ( ! Email || Email == null)
  4595. return;
  4596. var Title = prompt(email_title, theSelection);
  4597. if (Title == null)
  4598. return;
  4599. if (!Title || Title == "")
  4600. Title = Email;
  4601. var Link = '{' + 'encode="' + Email + '" title="' + Title + '"}';
  4602. // var Link = '<a href="mailto:' + Email + '">' + Title + '<'+'/a>';
  4603. }
  4604. if (which == "image")
  4605. {
  4606. var URL = prompt(image_text, "http://");
  4607. if ( ! URL || URL == null)
  4608. return;
  4609. var Link = '<img src="' + URL + '" />';
  4610. }
  4611. if (document.selection)
  4612. {
  4613. theField.focus();
  4614. document.selection.createRange().text = Link;
  4615. }
  4616. else if ( ! isNaN(theField.selectionEnd))
  4617. {
  4618. var newStart = s1.length + Link.length;
  4619. theField.value = s1 + Link + s3;
  4620. theField.focus();
  4621. theField.selectionStart = newStart;
  4622. theField.selectionEnd = newStart;
  4623. return;
  4624. }
  4625. else
  4626. {
  4627. eval("document.getElementById('entryform')." + selField + ".value += Link");
  4628. }
  4629. theSelection = '';
  4630. theField.blur();
  4631. theField.focus();
  4632. return;
  4633. }
  4634. // Close all tags
  4635. function closeall()
  4636. {
  4637. if (tagarray[0])
  4638. {
  4639. while (tagarray[0])
  4640. {
  4641. closeTag = arraypop(tagarray);
  4642. eval("document.getElementById('entryform')." + selField + ".value += closeTag");
  4643. }
  4644. }
  4645. clear_state();
  4646. running = 0;
  4647. curField = eval("document.getElementById('entryform')." + selField);
  4648. curField.focus();
  4649. }
  4650. //-->
  4651. </script>
  4652. <?php
  4653. $javascript = ob_get_contents();
  4654. ob_end_clean();
  4655. return $this->insert_javascript().$javascript.$r;
  4656. }
  4657. /* END */
  4658. /** ---------------------------------------------------------------
  4659. /** JavaScript For Inserting pMCode, Glossary, and Smileys
  4660. /** ---------------------------------------------------------------*/
  4661. function insert_javascript()
  4662. {
  4663. ob_start();
  4664. ?>
  4665. <script type="text/javascript">
  4666. <!--
  4667. var selField = false;
  4668. var selMode = "normal";
  4669. // Dynamically set the textarea name
  4670. function setFieldName(which)
  4671. {
  4672. if (which != selField)
  4673. {
  4674. selField = which;
  4675. clear_state();
  4676. tagarray = new Array();
  4677. usedarray = new Array();
  4678. running = 0;
  4679. }
  4680. }
  4681. // Insert tag
  4682. function taginsert(item, tagOpen, tagClose)
  4683. {
  4684. // Determine which tag we are dealing with
  4685. var which = eval('item.name');
  4686. if ( ! selField)
  4687. {
  4688. alert(no_cursor);
  4689. return false;
  4690. }
  4691. var theSelection = false;
  4692. var result = false
  4693. eval("var theField = document.getElementById('entryform')." + selField + ";");
  4694. if (selMode == 'guided')
  4695. {
  4696. data = prompt(enter_text, "");
  4697. if ((data != null) && (data != ""))
  4698. {
  4699. result = tagOpen + data + tagClose;
  4700. }
  4701. }
  4702. // Is this a Windows user?
  4703. // If so, add tags around selection
  4704. if (document.selection)
  4705. {
  4706. theSelection = document.selection.createRange().text;
  4707. theField.focus();
  4708. if (theSelection)
  4709. {
  4710. document.selection.createRange().text = (result == false) ? tagOpen + theSelection + tagClose : result;
  4711. }
  4712. else
  4713. {
  4714. document.selection.createRange().text = (result == false) ? tagOpen + tagClose : result;
  4715. }
  4716. theSelection = '';
  4717. theField.blur();
  4718. theField.focus();
  4719. return;
  4720. }
  4721. else if ( ! isNaN(theField.selectionEnd))
  4722. {
  4723. var scrollPos = theField.scrollTop;
  4724. var selLength = theField.textLength;
  4725. var selStart = theField.selectionStart;
  4726. var selEnd = theField.selectionEnd;
  4727. if (selEnd <= 2 && typeof(selLength) != 'undefined')
  4728. selEnd = selLength;
  4729. var s1 = (theField.value).substring(0,selStart);
  4730. var s2 = (theField.value).substring(selStart, selEnd)
  4731. var s3 = (theField.value).substring(selEnd, selLength);
  4732. if (result == false)
  4733. {
  4734. var newStart = selStart + tagOpen.length + s2.length + tagClose.length;
  4735. theField.value = (result == false) ? s1 + tagOpen + s2 + tagClose + s3 : result;
  4736. }
  4737. else
  4738. {
  4739. var newStart = selStart + result.length;
  4740. theField.value = s1 + result + s3;
  4741. }
  4742. theField.focus();
  4743. theField.selectionStart = newStart;
  4744. theField.selectionEnd = newStart;
  4745. theField.scrollTop = scrollPos;
  4746. return;
  4747. }
  4748. else if (selMode == 'guided')
  4749. {
  4750. eval("document.submit_post." + selField + ".value += result");
  4751. curField = eval("document.submit_post." + selField);
  4752. curField.blur();
  4753. curField.focus();
  4754. return;
  4755. }
  4756. // Add single open tags
  4757. if (item == 'other')
  4758. {
  4759. eval("document.getElementById('entryform')." + selField + ".value += tagOpen");
  4760. }
  4761. else if (eval(which) == 0)
  4762. {
  4763. var result = tagOpen;
  4764. eval("document.getElementById('entryform')." + selField + ".value += result");
  4765. eval(which + " = 1");
  4766. arraypush(tagarray, tagClose);
  4767. arraypush(usedarray, which);
  4768. running++;
  4769. styleswap(which);
  4770. }
  4771. else
  4772. {
  4773. // Close tags
  4774. n = 0;
  4775. for (i = 0 ; i < tagarray.length; i++ )
  4776. {
  4777. if (tagarray[i] == tagClose)
  4778. {
  4779. n = i;
  4780. running--;
  4781. while (tagarray[n])
  4782. {
  4783. closeTag = arraypop(tagarray);
  4784. eval("document.getElementById('entryform')." + selField + ".value += closeTag");
  4785. }
  4786. while (usedarray[n])
  4787. {
  4788. clearState = arraypop(usedarray);
  4789. eval(clearState + " = 0");
  4790. document.getElementById(clearState).className = 'htmlButtonA';
  4791. }
  4792. }
  4793. }
  4794. if (running <= 0 && document.getElementById('close_all').className == 'htmlButtonB')
  4795. {
  4796. document.getElementById('close_all').className = 'htmlButtonA';
  4797. }
  4798. }
  4799. curField = eval("document.getElementById('entryform')." + selField);
  4800. curField.blur();
  4801. curField.focus();
  4802. }
  4803. //-->
  4804. </script>
  4805. <?php
  4806. $javascript = ob_get_contents();
  4807. ob_end_clean();
  4808. return $javascript;
  4809. }
  4810. /* END */
  4811. /** ---------------------------------------------------------------
  4812. /** View previous pings
  4813. /** ---------------------------------------------------------------*/
  4814. // This function lets you look at trackback pings that you sent previously
  4815. //---------------------------------------------------------------
  4816. function view_previous_pings()
  4817. {
  4818. global $IN, $DSP, $LANG, $DB;
  4819. if ( ! $entry_id = $IN->GBL('entry_id', 'GP'))
  4820. {
  4821. return false;
  4822. }
  4823. if ( ! is_numeric($entry_id))
  4824. {
  4825. return false;
  4826. }
  4827. $query = $DB->query("SELECT sent_trackbacks FROM exp_weblog_titles WHERE entry_id = '$entry_id'");
  4828. if ($query->num_rows == 0)
  4829. {
  4830. return false;
  4831. }
  4832. $DSP->title = $LANG->line('view_previous_pings');
  4833. $DSP->crump = $LANG->line('view_previous_pings');
  4834. $DSP->body = $DSP->div('fieldWrapper').
  4835. $DSP->div('bold').
  4836. $LANG->line('previiously_pinged_urls').
  4837. $DSP->div_c().
  4838. $DSP->input_textarea('trackback_urls', $query->row['sent_trackbacks'], 12, 'textarea', '99%').
  4839. $DSP->div_c();
  4840. }
  4841. /* END */
  4842. //=====================================================================
  4843. // "EDIT" PAGE FUNCTIONS
  4844. //=====================================================================
  4845. /** --------------------------------------------
  4846. /** Edit weblogs page
  4847. /** --------------------------------------------*/
  4848. // This function is called when the EDIT tab is clicked
  4849. //--------------------------------------------
  4850. function edit_entries($weblog_id = '', $message = '')
  4851. {
  4852. global $LANG, $DSP;
  4853. $DSP->title = $LANG->line('edit_weblog_entries');
  4854. $DSP->crumb = $LANG->line('edit_weblog_entries');
  4855. $DSP->body .= $this->view_entries($weblog_id, $message);
  4856. }
  4857. /* END */
  4858. function view_entries($weblog_id = '', $message = '', $extra_sql = '', $search_url = '', $form_url = '', $action = '', $extra_fields_search='', $extra_fields_entries='')
  4859. {
  4860. global $IN, $LANG, $DSP, $FNS, $LOC, $DB, $SESS, $REGX, $PREFS, $EXT;
  4861. // Security check
  4862. if ( ! $DSP->allowed_group('can_access_edit'))
  4863. {
  4864. return $DSP->no_access_message();
  4865. }
  4866. /** --------------------------------------------
  4867. /** Fetch weblog ID numbers assigned to the current user
  4868. /** --------------------------------------------*/
  4869. $allowed_blogs = $FNS->fetch_assigned_weblogs();
  4870. if (empty($allowed_blogs))
  4871. {
  4872. return $DSP->no_access_message($LANG->line('no_weblogs'));
  4873. }
  4874. // -------------------------------------------
  4875. // 'edit_entries_start' hook.
  4876. // - Allows complete rewrite of Edit Entries page.
  4877. //
  4878. $edata = $EXT->call_extension('edit_entries_start', $weblog_id, $message);
  4879. if ($EXT->end_script === TRUE) return;
  4880. //
  4881. // -------------------------------------------
  4882. /** ------------------------------
  4883. /** Fetch Color Library
  4884. /** ------------------------------*/
  4885. // We use this to assist with our status colors
  4886. if (file_exists(PATH.'lib/colors'.EXT))
  4887. {
  4888. include (PATH.'lib/colors'.EXT);
  4889. }
  4890. else
  4891. {
  4892. $colors = '';
  4893. }
  4894. // We need to determine which weblog to show entries from.
  4895. // if the weblog_id global doesn't exist we'll show all weblogs
  4896. // combined
  4897. if ($weblog_id == '')
  4898. {
  4899. $weblog_id = $IN->GBL('weblog_id', 'GP');
  4900. }
  4901. if ($weblog_id == 'null' OR $weblog_id === FALSE OR ! is_numeric($weblog_id))
  4902. {
  4903. $weblog_id = '';
  4904. }
  4905. $cat_group = '';
  4906. $cat_id = $IN->GBL('cat_id', 'GP');
  4907. $status = $IN->GBL('status', 'GP');
  4908. $order = $IN->GBL('order', 'GP');
  4909. $date_range = $IN->GBL('date_range', 'GP');
  4910. $total_blogs = count($allowed_blogs);
  4911. // Begin building the page output
  4912. $r = $DSP->qdiv('tableHeading', $LANG->line('edit_weblog_entries'));
  4913. // Do we have a message to show?
  4914. // Note: a message is displayed on this page after editing or submitting a new entry
  4915. if ($IN->GBL("U") == 'mu')
  4916. {
  4917. $message = $DSP->qdiv('success', $LANG->line('multi_entries_updated'));
  4918. }
  4919. if ($message != '')
  4920. {
  4921. $r .= $message;
  4922. }
  4923. // Declare the "filtering" form
  4924. $s = $DSP->form_open(
  4925. array(
  4926. 'action' => ($search_url != '') ? $search_url : 'C=edit'.AMP.'M=view_entries',
  4927. 'name' => 'filterform',
  4928. 'id' => 'filterform'
  4929. )
  4930. );
  4931. $s .= $extra_fields_search;
  4932. // If we have more than one weblog we'll write the JavaScript menu switching code
  4933. if ($total_blogs > 1)
  4934. {
  4935. $s .= Publish::filtering_menus();
  4936. }
  4937. // Table start
  4938. $s .= $DSP->div('box');
  4939. $s .= $DSP->table('', '0', '', '100%').
  4940. $DSP->tr().
  4941. $DSP->td('itemWrapper', '', '7').NL;
  4942. // If we have more than one blog we'll add the "onchange" method to
  4943. // the form so that it'll automatically switch categories and statuses
  4944. if ($total_blogs > 1)
  4945. {
  4946. $s .= "<select name='weblog_id' class='select' onchange='changemenu(this.selectedIndex);'>\n";
  4947. }
  4948. else
  4949. {
  4950. $s .= "<select name='weblog_id' class='select'>\n";
  4951. }
  4952. // Design note: Becuase the JavaScript code dynamically switches the information inside the
  4953. // pull-down menus we can't show any particular menu in a "selected" state unless there is only
  4954. // one weblog. Remember that each weblog is fully independent, so it can have its own
  4955. // categories, statuses, etc.
  4956. // Weblog selection pull-down menu
  4957. // Fetch the names of all weblogs and write each one in an <option> field
  4958. $sql = "SELECT blog_title, weblog_id, cat_group FROM exp_weblogs";
  4959. // If the user is restricted to specific blogs, add that to the query
  4960. if ($SESS->userdata['group_id'] == 1)
  4961. {
  4962. $sql .= " WHERE is_user_blog = 'n'";
  4963. }
  4964. else
  4965. {
  4966. $sql .= " WHERE weblog_id IN (";
  4967. foreach ($allowed_blogs as $val)
  4968. {
  4969. $sql .= "'".$val."',";
  4970. }
  4971. $sql = substr($sql, 0, -1).')';
  4972. }
  4973. $sql .= " AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' order by blog_title";
  4974. $query = $DB->query($sql);
  4975. if ($query->num_rows == 1)
  4976. {
  4977. $weblog_id = $query->row['weblog_id'];
  4978. $cat_group = $query->row['cat_group'];
  4979. }
  4980. elseif($weblog_id != '')
  4981. {
  4982. foreach($query->result as $row)
  4983. {
  4984. if ($row['weblog_id'] == $weblog_id)
  4985. {
  4986. $weblog_id = $row['weblog_id'];
  4987. $cat_group = $row['cat_group'];
  4988. }
  4989. }
  4990. }
  4991. $s .= $DSP->input_select_option('null', $LANG->line('filter_by_weblog'));
  4992. if ($query->num_rows > 1)
  4993. {
  4994. $s .= $DSP->input_select_option('null', $LANG->line('all'));
  4995. }
  4996. $selected = '';
  4997. foreach ($query->result as $row)
  4998. {
  4999. if ($weblog_id != '')
  5000. {
  5001. $selected = ($weblog_id == $row['weblog_id']) ? 'y' : '';
  5002. }
  5003. $s .= $DSP->input_select_option($row['weblog_id'], $row['blog_title'], $selected);
  5004. }
  5005. $s .= $DSP->input_select_footer().
  5006. $DSP->nbs(2);
  5007. // Category pull-down menu
  5008. $s .= $DSP->input_select_header('cat_id').
  5009. $DSP->input_select_option('', $LANG->line('filter_by_category'));
  5010. if ($total_blogs > 1)
  5011. {
  5012. $s .= $DSP->input_select_option('all', $LANG->line('all'), ($cat_id == 'all') ? 'y' : '');
  5013. }
  5014. $s .= $DSP->input_select_option('none', $LANG->line('none'), ($cat_id == 'none') ? 'y' : '');
  5015. if ($cat_group != '')
  5016. {
  5017. if (TRUE)
  5018. {
  5019. $corder = ($this->nest_categories == 'y') ? 'group_id, parent_id, cat_name' : 'cat_name';
  5020. $query = $DB->query("SELECT cat_id, cat_name, group_id, parent_id FROM exp_categories WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY ".$corder);
  5021. $categories = array();
  5022. if ($query->num_rows > 0)
  5023. {
  5024. foreach ($query->result as $row)
  5025. {
  5026. $categories[] = array($row['group_id'], $row['cat_id'], $REGX->entities_to_ascii($row['cat_name']), $row['parent_id']);
  5027. }
  5028. if ($this->nest_categories == 'y')
  5029. {
  5030. $this->cat_array = array();
  5031. foreach($categories as $key => $val)
  5032. {
  5033. if (0 == $val['3'])
  5034. {
  5035. $this->cat_array[] = array($val['0'], $val['1'], $val['2']);
  5036. $this->category_edit_subtree($val['1'], $categories, $depth=1);
  5037. }
  5038. }
  5039. }
  5040. else
  5041. {
  5042. $this->cat_array = $categories;
  5043. }
  5044. }
  5045. foreach($this->cat_array as $key => $val)
  5046. {
  5047. if ( ! in_array($val['0'], explode('|',$cat_group)))
  5048. {
  5049. unset($this->cat_array[$key]);
  5050. }
  5051. }
  5052. }
  5053. foreach ($this->cat_array as $ckey => $cat)
  5054. {
  5055. if ($ckey-1 < 0 OR ! isset($this->cat_array[$ckey-1]))
  5056. {
  5057. $s .= $DSP->input_select_option('', '-------');
  5058. }
  5059. $s .= $DSP->input_select_option($cat['1'], str_replace('!-!', '&nbsp;', $cat['2']), (($cat_id == $cat['1']) ? 'y' : ''));
  5060. if (isset($this->cat_array[$ckey+1]) && $this->cat_array[$ckey+1]['0'] != $cat['0'])
  5061. {
  5062. $s .= $DSP->input_select_option('', '-------');
  5063. }
  5064. }
  5065. }
  5066. $s .= $DSP->input_select_footer().
  5067. $DSP->nbs(2);
  5068. // Status pull-down menu
  5069. $s .= $DSP->input_select_header('status').
  5070. $DSP->input_select_option('', $LANG->line('filter_by_status')).
  5071. $DSP->input_select_option('all', $LANG->line('all'), ($status == 'all') ? 1 : '');
  5072. if ($weblog_id != '')
  5073. {
  5074. $rez = $DB->query("SELECT status_group FROM exp_weblogs WHERE weblog_id = '$weblog_id'");
  5075. $query = $DB->query("SELECT status FROM exp_statuses WHERE group_id = '".$DB->escape_str($rez->row['status_group'])."' ORDER BY status_order");
  5076. if ($query->num_rows > 0)
  5077. {
  5078. foreach ($query->result as $row)
  5079. {
  5080. $selected = ($status == $row['status']) ? 1 : '';
  5081. $status_name = ($row['status'] == 'closed' OR $row['status'] == 'open') ? $LANG->line($row['status']) : $row['status'];
  5082. $s .= $DSP->input_select_option($row['status'], $status_name, $selected);
  5083. }
  5084. }
  5085. }
  5086. else
  5087. {
  5088. $s .= $DSP->input_select_option('open', $LANG->line('open'), ($status == 'open') ? 1 : '');
  5089. $s .= $DSP->input_select_option('closed', $LANG->line('closed'), ($status == 'closed') ? 1 : '');
  5090. }
  5091. $s .= $DSP->input_select_footer().
  5092. $DSP->nbs(2);
  5093. // Date range pull-down menu
  5094. $sel_1 = ($date_range == '1') ? 1 : '';
  5095. $sel_2 = ($date_range == '7') ? 1 : '';
  5096. $sel_3 = ($date_range == '31') ? 1 : '';
  5097. $sel_4 = ($date_range == '182') ? 1 : '';
  5098. $sel_5 = ($date_range == '365') ? 1 : '';
  5099. $s .= $DSP->input_select_header('date_range').
  5100. $DSP->input_select_option('', $LANG->line('date_range')).
  5101. $DSP->input_select_option('1', $LANG->line('today'), $sel_1).
  5102. $DSP->input_select_option('7', $LANG->line('past_week'), $sel_2).
  5103. $DSP->input_select_option('31', $LANG->line('past_month'), $sel_3).
  5104. $DSP->input_select_option('182', $LANG->line('past_six_months'), $sel_4).
  5105. $DSP->input_select_option('365', $LANG->line('past_year'), $sel_5).
  5106. $DSP->input_select_option('', $LANG->line('any_date')).
  5107. $DSP->input_select_footer().
  5108. $DSP->nbs(2);
  5109. // Display order pull-down menu
  5110. $sel_1 = ($order == 'desc') ? 1 : '';
  5111. $sel_2 = ($order == 'asc') ? 1 : '';
  5112. $sel_3 = ($order == 'alpha') ? 1 : '';
  5113. $s .= $DSP->input_select_header('order').
  5114. $DSP->input_select_option('desc', $LANG->line('order'), $sel_1).
  5115. $DSP->input_select_option('asc', $LANG->line('ascending'), $sel_2).
  5116. $DSP->input_select_option('desc', $LANG->line('descending'), $sel_1).
  5117. $DSP->input_select_option('alpha', $LANG->line('alpha'), $sel_3).
  5118. $DSP->input_select_footer().
  5119. $DSP->nbs(2);
  5120. // Results per page pull-down menu
  5121. if ( ! ($perpage = $IN->GBL('perpage', 'GP')))
  5122. {
  5123. $perpage = $IN->GBL('perpage', 'COOKIE');
  5124. }
  5125. if ($perpage == '')
  5126. $perpage = 50;
  5127. $FNS->set_cookie('perpage' , $perpage, 60*60*24*182);
  5128. $s .= $DSP->input_select_header('perpage').
  5129. $DSP->input_select_option('25', '25 '.$LANG->line('results'), ($perpage == 25) ? 1 : '').
  5130. $DSP->input_select_option('50', '50 '.$LANG->line('results'), ($perpage == 50) ? 1 : '').
  5131. $DSP->input_select_option('75', '75 '.$LANG->line('results'), ($perpage == 75) ? 1 : '').
  5132. $DSP->input_select_option('100', '100 '.$LANG->line('results'), ($perpage == 100) ? 1 : '').
  5133. $DSP->input_select_option('150', '150 '.$LANG->line('results'), ($perpage == 150) ? 1 : '').
  5134. $DSP->input_select_footer().
  5135. $DSP->nbs(2);
  5136. $s .= $DSP->td_c().
  5137. $DSP->tr_c().
  5138. $DSP->tr().
  5139. $DSP->td('itemWrapper', '', '7').NL;
  5140. if (isset($_POST['keywords']))
  5141. {
  5142. $keywords = $REGX->keyword_clean($_POST['keywords']);
  5143. }
  5144. elseif (isset($_GET['keywords']))
  5145. {
  5146. $keywords = $REGX->keyword_clean(base64_decode($_GET['keywords']));
  5147. }
  5148. else
  5149. {
  5150. $keywords = '';
  5151. }
  5152. if (substr(strtolower($keywords), 0, 3) == 'ip:')
  5153. {
  5154. $keywords = str_replace('_','.',$keywords);
  5155. }
  5156. // Because of the auto convert we prepare a specific variable
  5157. // with the converted ascii characters while leaving the $keywords
  5158. // variable intact for display and URL purposes
  5159. $search_keywords = ($PREFS->ini('auto_convert_high_ascii') == 'y') ? $REGX->ascii_to_entities($keywords) : $keywords;
  5160. $exact_match = ($IN->GBL('exact_match', 'GP') != '') ? $IN->GBL('exact_match', 'GP') : '';
  5161. $s .= $DSP->div('default').$LANG->line('keywords', 'keywords').NBS.NBS;
  5162. $s .= $DSP->input_text('keywords', stripslashes($keywords), '40', '200', 'input', '200px').NBS.NBS;
  5163. $s .= $DSP->input_checkbox('exact_match', 'yes', $exact_match).NBS.$LANG->line('exact_match').NBS.NBS;
  5164. $search_in = ($IN->GBL('search_in', 'GP') != '') ? $IN->GBL('search_in', 'GP') : 'title';
  5165. $s .= $DSP->input_select_header('search_in').
  5166. $DSP->input_select_option('title', $LANG->line('title_only'), ($search_in == 'title') ? 1 : '').
  5167. $DSP->input_select_option('body', $LANG->line('title_and_body'), ($search_in == 'body') ? 1 : '').
  5168. $DSP->input_select_option('everywhere', $LANG->line('title_body_comments'), ($search_in == 'everywhere') ? 1 : '').
  5169. (( ! isset($this->installed_modules['comment'])) ? '' : $DSP->input_select_option('comments', $LANG->line('comments'), ($search_in == 'comments') ? 1 : '')).
  5170. (( ! isset($this->installed_modules['trackback'])) ? '' : $DSP->input_select_option('trackbacks', $LANG->line('trackbacks'), ($search_in == 'trackbacks') ? 1 : '')).
  5171. $DSP->input_select_footer().
  5172. $DSP->nbs(2);
  5173. // Submit button and form close
  5174. $s .= $DSP->input_submit($LANG->line('search'), 'submit');
  5175. $s .= $DSP->div_c();
  5176. $s .= $DSP->td_c().
  5177. $DSP->tr_c().
  5178. $DSP->table_c();
  5179. $s .= $DSP->div_c();
  5180. $s .= $DSP->form_close();
  5181. // -------------------------------------------
  5182. // 'edit_entries_search_form' hook.
  5183. // - Allows complete rewrite of Edit Entries Search form.
  5184. //
  5185. if ($EXT->active_hook('edit_entries_search_form') === TRUE)
  5186. {
  5187. $r .= $EXT->call_extension('edit_entries_search_form', $s);
  5188. if ($EXT->end_script === TRUE) return;
  5189. }
  5190. else
  5191. {
  5192. $r .= $s;
  5193. }
  5194. //
  5195. // -------------------------------------------
  5196. /** ------------------------------
  5197. /** Build the main query
  5198. /** ------------------------------*/
  5199. if ($search_url != '')
  5200. {
  5201. $pageurl = BASE.AMP.$search_url;
  5202. }
  5203. else
  5204. {
  5205. $pageurl = BASE.AMP.'C=edit'.AMP.'M=view_entries';
  5206. }
  5207. $sql_a = "SELECT ";
  5208. if ($search_in == 'comments')
  5209. {
  5210. $sql_b = "DISTINCT(exp_comments.comment_id) ";
  5211. }
  5212. elseif ($search_in == 'trackbacks')
  5213. {
  5214. $sql_b = "DISTINCT(exp_trackbacks.trackback_id) ";
  5215. }
  5216. else
  5217. {
  5218. $sql_b = ($cat_id == 'none' || $cat_id != "") ? "DISTINCT(exp_weblog_titles.entry_id) " : "exp_weblog_titles.entry_id ";
  5219. }
  5220. $sql = "FROM exp_weblog_titles
  5221. LEFT JOIN exp_weblogs ON exp_weblog_titles.weblog_id = exp_weblogs.weblog_id ";
  5222. if ($keywords != '')
  5223. {
  5224. if ($search_in != 'title')
  5225. $sql .= "LEFT JOIN exp_weblog_data ON exp_weblog_titles.entry_id = exp_weblog_data.entry_id ";
  5226. if ($search_in == 'everywhere' OR $search_in == 'comments')
  5227. {
  5228. $sql .= "LEFT JOIN exp_comments ON exp_weblog_titles.entry_id = exp_comments.entry_id ";
  5229. }
  5230. elseif($search_in == 'trackbacks')
  5231. {
  5232. $sql .= "LEFT JOIN exp_trackbacks ON exp_weblog_titles.entry_id = exp_trackbacks.entry_id ";
  5233. }
  5234. }
  5235. elseif ($search_in == 'comments')
  5236. {
  5237. $sql .= "LEFT JOIN exp_comments ON exp_weblog_titles.entry_id = exp_comments.entry_id ";
  5238. }
  5239. elseif ($search_in == 'trackbacks')
  5240. {
  5241. $sql .= "LEFT JOIN exp_trackbacks ON exp_weblog_titles.entrY_id = exp_trackbacks.entry_id ";
  5242. }
  5243. $sql .= "LEFT JOIN exp_members ON exp_members.member_id = exp_weblog_titles.author_id ";
  5244. if ($cat_id == 'none' || $cat_id != "")
  5245. {
  5246. $sql .= "LEFT JOIN exp_category_posts ON exp_weblog_titles.entry_id = exp_category_posts.entry_id
  5247. LEFT JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id ";
  5248. }
  5249. if (is_array($extra_sql) && isset($extra_sql['tables']))
  5250. {
  5251. $sql .= ' '.$extra_sql['tables'].' ';
  5252. }
  5253. // -------------------------------------------
  5254. // 'edit_entries_search_tables' hook.
  5255. // - Add additional parts to the TABLES part of query
  5256. //
  5257. if ($EXT->active_hook('edit_entries_search_tables') === TRUE)
  5258. {
  5259. $sql .= $EXT->call_extension('edit_entries_search_tables');
  5260. }
  5261. //
  5262. // -------------------------------------------
  5263. // Limit to weblogs assigned to user
  5264. if ($SESS->userdata('member_id') == 0)
  5265. {
  5266. $sql .= " WHERE is_user_blog = 'n' AND exp_weblogs.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  5267. }
  5268. else
  5269. {
  5270. $sql .= " WHERE exp_weblogs.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND exp_weblog_titles.weblog_id IN (";
  5271. foreach ($allowed_blogs as $val)
  5272. {
  5273. $sql .= "'".$val."',";
  5274. }
  5275. $sql = substr($sql, 0, -1).')';
  5276. if ( ! $DSP->allowed_group('can_edit_other_entries') AND ! $DSP->allowed_group('can_view_other_entries'))
  5277. {
  5278. $sql .= " AND exp_weblog_titles.author_id = ".$SESS->userdata('member_id');
  5279. }
  5280. }
  5281. if (is_array($extra_sql) && isset($extra_sql['where']))
  5282. {
  5283. $sql .= ' '.$extra_sql['where'].' ';
  5284. }
  5285. if ($keywords != '')
  5286. {
  5287. $pageurl .= AMP.'keywords='.base64_encode($keywords);
  5288. if ($search_in == 'trackbacks' OR $search_in == 'comments')
  5289. {
  5290. // When searching in comments and trackbacks we do not want to
  5291. // search the entry title. However, by removing this we would
  5292. // have to make the rest of the query creation code below really messy
  5293. // so we simply check for an empty title, which should never happen.
  5294. // That makes this check pointless and allows us some cleaner code. -Paul
  5295. $sql .= " AND (exp_weblog_titles.title = '' ";
  5296. }
  5297. else
  5298. {
  5299. if ($exact_match != 'yes')
  5300. {
  5301. $sql .= " AND (exp_weblog_titles.title LIKE '%".$DB->escape_like_str($search_keywords)."%' ";
  5302. }
  5303. else
  5304. {
  5305. $pageurl .= AMP.'exact_match=yes';
  5306. $sql .= " AND (exp_weblog_titles.title = '".$DB->escape_str($search_keywords)."' OR exp_weblog_titles.title LIKE '".$DB->escape_like_str($search_keywords)." %' OR exp_weblog_titles.title LIKE '% ".$DB->escape_like_str($search_keywords)." %' ";
  5307. }
  5308. }
  5309. $pageurl .= AMP.'search_in='.$search_in;
  5310. if ($search_in == 'body' OR $search_in == 'everywhere')
  5311. {
  5312. /** ---------------------------------------
  5313. /** Fetch the searchable field names
  5314. /** ---------------------------------------*/
  5315. $fields = array();
  5316. $xql = "SELECT DISTINCT(field_group) FROM exp_weblogs WHERE ";
  5317. $xql .= (USER_BLOG !== FALSE) ? "weblog_id = '".UB_BLOG_ID."' " : "is_user_blog = 'n' ";
  5318. if ($weblog_id != '')
  5319. {
  5320. $xql .= " AND weblog_id = '".$DB->escape_str($weblog_id)."' ";
  5321. }
  5322. $query = $DB->query($xql);
  5323. if ($query->num_rows > 0)
  5324. {
  5325. $fql = "SELECT field_id, field_type FROM exp_weblog_fields WHERE group_id IN (";
  5326. foreach ($query->result as $row)
  5327. {
  5328. $fql .= "'".$row['field_group']."',";
  5329. }
  5330. $fql = substr($fql, 0, -1).')';
  5331. $query = $DB->query($fql);
  5332. if ($query->num_rows > 0)
  5333. {
  5334. foreach ($query->result as $row)
  5335. {
  5336. if ($row['field_type'] == 'text' OR $row['field_type'] == 'textarea' OR $row['field_type'] == 'select')
  5337. {
  5338. $fields[] = $row['field_id'];
  5339. }
  5340. }
  5341. }
  5342. }
  5343. foreach ($fields as $val)
  5344. {
  5345. if ($exact_match != 'yes')
  5346. {
  5347. $sql .= " OR exp_weblog_data.field_id_".$val." LIKE '%".$DB->escape_like_str($search_keywords)."%' ";
  5348. }
  5349. else
  5350. {
  5351. $sql .= " OR (exp_weblog_data.field_id_".$val." LIKE '".$DB->escape_like_str($search_keywords)." %' OR exp_weblog_data.field_id_".$val." LIKE '% ".$DB->escape_like_str($search_keywords)." %' OR exp_weblog_data.field_id_".$val." = '".$DB->escape_str($search_keywords)."') ";
  5352. }
  5353. }
  5354. }
  5355. if ($search_in == 'everywhere' OR $search_in == 'comments')
  5356. {
  5357. if ($search_in == 'comments' && (substr(strtolower($search_keywords), 0, 3) == 'ip:' OR substr(strtolower($search_keywords), 0, 4) == 'mid:'))
  5358. {
  5359. if (substr(strtolower($search_keywords), 0, 3) == 'ip:')
  5360. {
  5361. $sql .= " OR (exp_comments.ip_address = '".$DB->escape_str(str_replace('_','.',substr($search_keywords, 3)))."') ";
  5362. }
  5363. elseif(substr(strtolower($search_keywords), 0, 4) == 'mid:')
  5364. {
  5365. $sql .= " OR (exp_comments.author_id = '".$DB->escape_str(substr($search_keywords, 4))."') ";
  5366. }
  5367. }
  5368. else
  5369. {
  5370. $sql .= " OR (exp_comments.comment LIKE '%".$DB->escape_like_str($keywords)."%') "; // No ASCII conversion here!
  5371. }
  5372. }
  5373. elseif ($search_in == 'trackbacks')
  5374. {
  5375. if ($search_in == 'trackbacks' && substr(strtolower($search_keywords), 0, 3) == 'ip:')
  5376. {
  5377. $sql .= " OR (exp_trackbacks.trackback_ip = '".$DB->escape_str(str_replace('_','.',substr($search_keywords, 3)))."') ";
  5378. }
  5379. else
  5380. {
  5381. $sql .= " OR (CONCAT_WS(' ', exp_trackbacks.content, exp_trackbacks.title, exp_trackbacks.weblog_name) LIKE '%".$DB->escape_like_str($keywords)."%') "; // No ASCII conversion here either!
  5382. }
  5383. }
  5384. $sql .= ")";
  5385. }
  5386. if ($weblog_id)
  5387. {
  5388. $pageurl .= AMP.'weblog_id='.$weblog_id;
  5389. $sql .= " AND exp_weblog_titles.weblog_id = $weblog_id";
  5390. }
  5391. if ($date_range)
  5392. {
  5393. $pageurl .= AMP.'date_range='.$date_range;
  5394. $date_range = time() - ($date_range * 60 * 60 * 24);
  5395. $sql .= " AND exp_weblog_titles.entry_date > $date_range";
  5396. }
  5397. if (is_numeric($cat_id))
  5398. {
  5399. $pageurl .= AMP.'cat_id='.$cat_id;
  5400. $sql .= " AND exp_category_posts.cat_id = '$cat_id'
  5401. AND exp_category_posts.entry_id = exp_weblog_titles.entry_id ";
  5402. }
  5403. if ($cat_id == 'none')
  5404. {
  5405. $pageurl .= AMP.'cat_id='.$cat_id;
  5406. $sql .= " AND exp_category_posts.entry_id IS NULL ";
  5407. }
  5408. if ($status && $status != 'all')
  5409. {
  5410. $pageurl .= AMP.'status='.$status;
  5411. $sql .= " AND exp_weblog_titles.status = '$status'";
  5412. }
  5413. // -------------------------------------------
  5414. // 'edit_entries_search_where' hook.
  5415. // - Add additional parts to the WHERE clause of search
  5416. //
  5417. if ($EXT->active_hook('edit_entries_search_where') === TRUE)
  5418. {
  5419. $sql .= $EXT->call_extension('edit_entries_search_where');
  5420. }
  5421. //
  5422. // -------------------------------------------
  5423. $end = " ORDER BY ";
  5424. if ($order)
  5425. {
  5426. $pageurl .= AMP.'order='.$order;
  5427. switch ($order)
  5428. {
  5429. case 'asc' : $end .= "entry_date asc";
  5430. break;
  5431. case 'desc' : $end .= "entry_date desc";
  5432. break;
  5433. case 'alpha' : $end .= "title asc";
  5434. break;
  5435. default : $end .= "entry_date desc";
  5436. }
  5437. }
  5438. else
  5439. {
  5440. $end .= "entry_date desc";
  5441. }
  5442. /** ------------------------------
  5443. /** Are there results?
  5444. /** ------------------------------*/
  5445. $query = $DB->query($sql_a.$sql_b.$sql);
  5446. // No result? Show the "no results" message
  5447. $total_count = $query->num_rows;
  5448. if ($total_count == 0)
  5449. {
  5450. $r .= $DSP->qdiv('highlight', BR.$LANG->line('no_entries_matching_that_criteria'));
  5451. return $DSP->set_return_data(
  5452. $LANG->line('edit').$DSP->crumb_item($LANG->line('edit_weblog_entries')),
  5453. $r,
  5454. $LANG->line('edit_weblog_entries')
  5455. );
  5456. }
  5457. // Get the current row number and add the LIMIT clause to the SQL query
  5458. if ( ! $rownum = $IN->GBL('rownum', 'GP'))
  5459. {
  5460. $rownum = 0;
  5461. }
  5462. /** --------------------------------------------
  5463. /** Run the query again, fetching ID numbers
  5464. /** --------------------------------------------*/
  5465. $query = $DB->query($sql_a.$sql_b.$sql.$end." LIMIT ".$rownum.", ".$perpage);
  5466. $pageurl .= AMP.'perpage='.$perpage;
  5467. if ($search_in == 'comments')
  5468. {
  5469. $comment_array = array();
  5470. foreach ($query->result as $row)
  5471. {
  5472. $comment_array[] = $row['comment_id'];
  5473. }
  5474. if ($keywords == '')
  5475. {
  5476. $pageurl .= AMP.'keywords='.base64_encode($keywords).AMP.'search_in='.$search_in;
  5477. }
  5478. $pagination_links = $DSP->pager($pageurl, $total_count, $perpage, $rownum, 'rownum');
  5479. return $this->view_comments('', '', '', FALSE, array_unique($comment_array), $pagination_links, $rownum);
  5480. }
  5481. elseif ($search_in == 'trackbacks')
  5482. {
  5483. $trackback_array = array();
  5484. foreach ($query->result as $row)
  5485. {
  5486. $trackback_array[] = $row['trackback_id'];
  5487. }
  5488. if ($keywords == '')
  5489. {
  5490. $pageurl .= AMP.'keywords='.base64_encode($keywords).AMP.'search_in='.$search_in;
  5491. }
  5492. $pagination_links = $DSP->pager($pageurl, $total_count, $perpage, $rownum, 'rownum');
  5493. return $this->view_comments('', '', $message, TRUE, array_unique($trackback_array));
  5494. }
  5495. /** --------------------------------------------
  5496. /** Fetch the weblog information we need later
  5497. /** --------------------------------------------*/
  5498. $sql = "SELECT weblog_id, blog_name FROM exp_weblogs ";
  5499. if (USER_BLOG !== FALSE)
  5500. {
  5501. $sql .= " WHERE exp_weblogs.weblog_id = '".UB_BLOG_ID."'";
  5502. }
  5503. else
  5504. {
  5505. $sql .= " WHERE exp_weblogs.is_user_blog = 'n'";
  5506. }
  5507. $sql .= "AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ";
  5508. $w_array = array();
  5509. $result = $DB->query($sql);
  5510. if ($result->num_rows > 0)
  5511. {
  5512. foreach ($result->result as $rez)
  5513. {
  5514. $w_array[$rez['weblog_id']] = $rez['blog_name'];
  5515. }
  5516. }
  5517. /** --------------------------------------------
  5518. /** Fetch the status highlight colors
  5519. /** --------------------------------------------*/
  5520. $cql = "SELECT exp_weblogs.weblog_id, exp_weblogs.blog_name, exp_statuses.status, exp_statuses.highlight
  5521. FROM exp_weblogs, exp_statuses, exp_status_groups
  5522. WHERE exp_status_groups.group_id = exp_weblogs.status_group
  5523. AND exp_status_groups.group_id = exp_statuses.group_id
  5524. AND exp_statuses.highlight != ''
  5525. AND exp_status_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ";
  5526. // Limit to weblogs assigned to user
  5527. if ($SESS->userdata['weblog_id'] != 0)
  5528. {
  5529. $sql .= " AND exp_weblogs.weblog_id IN (";
  5530. foreach ($allowed_blogs as $val)
  5531. {
  5532. $sql .= "'".$val."',";
  5533. }
  5534. $sql = substr($sql, 0, -1).')';
  5535. }
  5536. else
  5537. {
  5538. $cql .= " AND is_user_blog = 'n'";
  5539. }
  5540. $result = $DB->query($cql);
  5541. $c_array = array();
  5542. if ($result->num_rows > 0)
  5543. {
  5544. foreach ($result->result as $rez)
  5545. {
  5546. $c_array[$rez['weblog_id'].'_'.$rez['status']] = str_replace('#', '', $rez['highlight']);
  5547. }
  5548. }
  5549. // "select all" checkbox
  5550. $r .= $DSP->toggle();
  5551. $DSP->body_props .= ' onload="magic_check()" ';
  5552. $r .= $DSP->magic_checkboxes();
  5553. // Build the item headings
  5554. // Declare the "multi edit actions" form
  5555. $r .= $DSP->form_open(
  5556. array(
  5557. 'action' => ($form_url != '') ? $form_url : 'C=edit'.AMP.'M=multi_edit',
  5558. 'name' => 'target',
  5559. 'id' => 'target'
  5560. )
  5561. );
  5562. $r .= $extra_fields_entries;
  5563. /** --------------------------------------------
  5564. /** Build the output table
  5565. /** --------------------------------------------*/
  5566. $o = $DSP->table('tableBorder', '0', '', '100%').
  5567. $DSP->tr().
  5568. $DSP->table_qcell('tableHeadingAlt', '#').
  5569. $DSP->table_qcell('tableHeadingAlt', $LANG->line('title')).
  5570. $DSP->table_qcell('tableHeadingAlt', $LANG->line('view')).
  5571. (( ! isset($this->installed_modules['comment'])) ? '' : $DSP->table_qcell('tableHeadingAlt', $LANG->line('comments'))).
  5572. (( ! isset($this->installed_modules['trackback'])) ? '' : $DSP->table_qcell('tableHeadingAlt', $LANG->line('trackbacks'))).
  5573. $DSP->table_qcell('tableHeadingAlt', $LANG->line('author')).
  5574. $DSP->table_qcell('tableHeadingAlt', $LANG->line('date')).
  5575. $DSP->table_qcell('tableHeadingAlt', $LANG->line('weblog')).
  5576. $DSP->table_qcell('tableHeadingAlt', $LANG->line('status'));
  5577. // -------------------------------------------
  5578. // 'edit_entries_additional_tableheader' hook.
  5579. // - Add another cell row to display, title here
  5580. //
  5581. if ($EXT->active_hook('edit_entries_additional_tableheader') === TRUE)
  5582. {
  5583. $o .= $EXT->call_extension('edit_entries_additional_tableheader', $query->row);
  5584. }
  5585. //
  5586. // -------------------------------------------
  5587. $o .= $DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"")).
  5588. $DSP->tr_c();
  5589. // -------------------------------------------
  5590. // 'edit_entries_modify_tableheader' hook.
  5591. // - Allows modifying or rewrite of Edit sections Table Header.
  5592. //
  5593. if ($EXT->active_hook('edit_entries_modify_tableheader') === TRUE)
  5594. {
  5595. $r .= $EXT->call_extension('edit_entries_modify_tableheader', $o);
  5596. if ($EXT->end_script === TRUE) return;
  5597. }
  5598. else
  5599. {
  5600. $r .= $o;
  5601. }
  5602. //
  5603. // -------------------------------------------
  5604. /** ----------------------------------------------
  5605. /** Build and run the full SQL query
  5606. /** ----------------------------------------------*/
  5607. $sql = "SELECT ";
  5608. $sql .= ($cat_id == 'none' || $cat_id != "") ? "DISTINCT(exp_weblog_titles.entry_id), " : "exp_weblog_titles.entry_id, ";
  5609. $sql .= "exp_weblog_titles.weblog_id,
  5610. exp_weblog_titles.title,
  5611. exp_weblog_titles.author_id,
  5612. exp_weblog_titles.status,
  5613. exp_weblog_titles.entry_date,
  5614. exp_weblog_titles.dst_enabled,
  5615. exp_weblog_titles.comment_total,
  5616. exp_weblog_titles.trackback_total,
  5617. exp_weblogs.live_look_template,
  5618. exp_members.username,
  5619. exp_members.email,
  5620. exp_members.screen_name";
  5621. // -------------------------------------------
  5622. // 'edit_entries_search_fields' hook.
  5623. // - Add additional parts to the FIELDS part of query
  5624. //
  5625. if ($EXT->active_hook('edit_entries_search_fields') === TRUE)
  5626. {
  5627. $sql .= $EXT->call_extension('edit_entries_search_fields');
  5628. }
  5629. //
  5630. // -------------------------------------------
  5631. $sql .= " FROM exp_weblog_titles
  5632. LEFT JOIN exp_weblogs ON exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  5633. LEFT JOIN exp_members ON exp_members.member_id = exp_weblog_titles.author_id ";
  5634. if ($cat_id != 'none' AND $cat_id != "")
  5635. {
  5636. $sql .= "INNER JOIN exp_category_posts ON exp_weblog_titles.entry_id = exp_category_posts.entry_id
  5637. INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id ";
  5638. }
  5639. $sql .= "WHERE exp_weblog_titles.entry_id IN (";
  5640. foreach ($query->result as $row)
  5641. {
  5642. $sql .= $row['entry_id'].',';
  5643. }
  5644. $sql = substr($sql, 0, -1).') '.$end;
  5645. $query = $DB->query($sql);
  5646. // load the site's templates
  5647. $templates = array();
  5648. $tquery = $DB->query("SELECT exp_template_groups.group_name, exp_templates.template_name, exp_templates.template_id
  5649. FROM exp_template_groups, exp_templates
  5650. WHERE exp_template_groups.group_id = exp_templates.group_id
  5651. AND exp_templates.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  5652. if ($tquery->num_rows > 0)
  5653. {
  5654. foreach ($tquery->result as $row)
  5655. {
  5656. $templates[$row['template_id']] = $row['group_name'].'/'.$row['template_name'];
  5657. }
  5658. }
  5659. // Loop through the main query result and write each table row
  5660. $i = 0;
  5661. foreach($query->result as $row)
  5662. {
  5663. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  5664. $tr = $DSP->tr();
  5665. // Entry ID number
  5666. $tr .= $DSP->table_qcell($style, $row['entry_id']);
  5667. // Weblog entry title (view entry)
  5668. $tr .= $DSP->table_qcell($style,
  5669. $DSP->anchor(
  5670. BASE.AMP.'C=edit'.AMP.'M=edit_entry'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'],
  5671. '<b>'.$row['title'].'</b>'
  5672. )
  5673. );
  5674. // Edit entry
  5675. $show_link = TRUE;
  5676. if ($row['live_look_template'] != 0 && isset($templates[$row['live_look_template']]))
  5677. {
  5678. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  5679. $view_link = $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.
  5680. $FNS->create_url($templates[$row['live_look_template']].'/'.$row['entry_id']),
  5681. $LANG->line('live_look'), '', TRUE);
  5682. }
  5683. else
  5684. {
  5685. if (($row['author_id'] != $SESS->userdata('member_id')) && ! $DSP->allowed_group('can_edit_other_entries'))
  5686. {
  5687. $show_link = FALSE;
  5688. }
  5689. $view_url = BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'];
  5690. $view_link = ($show_link == FALSE) ? '--' : $DSP->anchor($view_url, $LANG->line('view'));
  5691. }
  5692. $tr .= $DSP->table_qcell($style, $view_link);
  5693. // Comment count
  5694. $show_link = TRUE;
  5695. if ($row['author_id'] == $SESS->userdata('member_id'))
  5696. {
  5697. if ( ! $DSP->allowed_group('can_edit_own_comments') AND
  5698. ! $DSP->allowed_group('can_delete_own_comments') AND
  5699. ! $DSP->allowed_group('can_moderate_comments'))
  5700. {
  5701. $show_link = FALSE;
  5702. }
  5703. }
  5704. else
  5705. {
  5706. if ( ! $DSP->allowed_group('can_edit_all_comments') AND
  5707. ! $DSP->allowed_group('can_delete_all_comments') AND
  5708. ! $DSP->allowed_group('can_moderate_comments'))
  5709. {
  5710. $show_link = FALSE;
  5711. }
  5712. }
  5713. if ( isset($this->installed_modules['comment']))
  5714. {
  5715. // Comment Link
  5716. if ($show_link !== FALSE)
  5717. {
  5718. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$row['entry_id']."'");$DB->q_count--;
  5719. $view_url = BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'];
  5720. }
  5721. $view_link = ($show_link == FALSE) ? $DSP->qdiv('lightLinks', '--') : $DSP->qspan('lightLinks', '('.($res->row['count']).')').NBS.$DSP->anchor($view_url, $LANG->line('view'));
  5722. $tr .= $DSP->table_qcell($style, $view_link);
  5723. }
  5724. if ( isset($this->installed_modules['trackback']))
  5725. {
  5726. // Trackback Link
  5727. if ($show_link !== FALSE)
  5728. {
  5729. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_trackbacks WHERE entry_id = '".$row['entry_id']."'");$DB->q_count--;
  5730. $view_url = BASE.AMP.'C=edit'.AMP.'M=view_trackbacks'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'];
  5731. }
  5732. $view_link = ($show_link == FALSE) ? $DSP->qdiv('lightLinks', '--') : $DSP->qspan('lightLinks', '('.($res->row['count']).')').NBS.$DSP->anchor($view_url, $LANG->line('view'));
  5733. $tr .= $DSP->table_qcell($style, $view_link);
  5734. }
  5735. // Username
  5736. $name = ($row['screen_name'] != '') ? $row['screen_name'] : $row['username'];
  5737. $name = $DSP->anchor('mailto:'.$row['email'], $name, 'title="Send an email to '.$name.'"');
  5738. $tr .= $DSP->table_qcell($style, $DSP->qdiv('smallLinks', $name));
  5739. // Date
  5740. $date_fmt = ($SESS->userdata['time_format'] != '') ? $SESS->userdata['time_format'] : $PREFS->ini('time_format');
  5741. if ($date_fmt == 'us')
  5742. {
  5743. $datestr = '%m/%d/%y %h:%i %a';
  5744. }
  5745. else
  5746. {
  5747. $datestr = '%Y-%m-%d %H:%i';
  5748. }
  5749. if ($PREFS->ini('honor_entry_dst') == 'y')
  5750. {
  5751. if ($row['dst_enabled'] == 'n' AND $SESS->userdata('daylight_savings') == 'y')
  5752. {
  5753. if ($row['entry_date'] != '')
  5754. $row['entry_date'] -= 3600;
  5755. }
  5756. elseif ($row['dst_enabled'] == 'y' AND $SESS->userdata('daylight_savings') == 'n')
  5757. {
  5758. if ($row['entry_date'] != '')
  5759. $row['entry_date'] += 3600;
  5760. }
  5761. }
  5762. // -------------------------------------------
  5763. // 'edit_entries_decode_date' hook.
  5764. // - Change how the date is formatted in the edit entries list
  5765. //
  5766. if ($EXT->active_hook('edit_entries_decode_date') === TRUE)
  5767. {
  5768. $tr .= $EXT->call_extension('edit_entries_decode_date', $row['entry_date']);
  5769. }
  5770. else
  5771. {
  5772. $tr .= $DSP->td($style).$DSP->qdiv('smallNoWrap', $LOC->decode_date($datestr, $row['entry_date'], TRUE)).$DSP->td_c();
  5773. }
  5774. //
  5775. // -------------------------------------------
  5776. // Weblog
  5777. $tr .= $DSP->table_qcell($style, (isset($w_array[$row['weblog_id']])) ? $DSP->qdiv('smallNoWrap', $w_array[$row['weblog_id']]) : '');
  5778. // Status
  5779. $tr .= $DSP->td($style);
  5780. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? $LANG->line($row['status']) : $row['status'];
  5781. if (isset($c_array[$row['weblog_id'].'_'.$row['status']]) AND $c_array[$row['weblog_id'].'_'.$row['status']] != '')
  5782. {
  5783. $color = $c_array[$row['weblog_id'].'_'.$row['status']];
  5784. $prefix = (is_array($colors) AND ! array_key_exists(strtolower($color), $colors)) ? '#' : '';
  5785. $tr .= "<div style='color:".$prefix.$color.";'>".$status_name.'</div>';
  5786. }
  5787. else
  5788. {
  5789. if ($row['status'] == 'open')
  5790. {
  5791. $tr .= "<div style='color:#009933;'>".$status_name.'</div>';
  5792. }
  5793. elseif ($row['status'] == 'closed')
  5794. {
  5795. $tr .= "<div style='color:#990000;'>".$status_name.'</div>';
  5796. }
  5797. else
  5798. {
  5799. $tr .= $status_name;
  5800. }
  5801. }
  5802. $tr .= $DSP->td_c();
  5803. // -------------------------------------------
  5804. // 'edit_entries_additional_celldata' hook.
  5805. // - Add another cell to display?
  5806. //
  5807. if ($EXT->active_hook('edit_entries_additional_celldata') === TRUE)
  5808. {
  5809. $tr .= $EXT->call_extension('edit_entries_additional_celldata', $row);
  5810. }
  5811. //
  5812. // -------------------------------------------
  5813. // Delete checkbox
  5814. $tr .= $DSP->table_qcell($style, $DSP->input_checkbox('toggle[]', $row['entry_id'], '' , ' id="delete_box_'.$row['entry_id'].'"'));
  5815. $tr .= $DSP->tr_c();
  5816. // -------------------------------------------
  5817. // 'edit_entries_modify_tablerow' hook.
  5818. // - Allows modifying or rewrite of entry row in Edit section.
  5819. //
  5820. if ($EXT->active_hook('edit_entries_modify_tablerow') === TRUE)
  5821. {
  5822. $r .= $EXT->call_extension('edit_entries_modify_tablerow', $tr);
  5823. if ($EXT->end_script === TRUE) return;
  5824. }
  5825. else
  5826. {
  5827. $r .= $tr;
  5828. }
  5829. //
  5830. // -------------------------------------------
  5831. } // End foreach
  5832. $r .= $DSP->table_c();
  5833. $r .= $DSP->table('', '0', '', '100%');
  5834. $r .= $DSP->tr().
  5835. $DSP->td();
  5836. // Pass the relevant data to the paginate class
  5837. $r .= $DSP->div('crumblinks').
  5838. $DSP->pager(
  5839. $pageurl,
  5840. $total_count,
  5841. $perpage,
  5842. $rownum,
  5843. 'rownum'
  5844. ).
  5845. $DSP->div_c().
  5846. $DSP->td_c().
  5847. $DSP->td('defaultRight');
  5848. $r .= $DSP->input_hidden('pageurl', base64_encode($pageurl));
  5849. // Delete button
  5850. $r .= $DSP->div('itemWrapper');
  5851. $r .= $DSP->input_submit($LANG->line('submit'));
  5852. if ($action == '')
  5853. {
  5854. $r .= NBS.$DSP->input_select_header('action').
  5855. $DSP->input_select_option('edit', $LANG->line('edit_selected')).
  5856. $DSP->input_select_option('delete', $LANG->line('delete_selected')).
  5857. $DSP->input_select_option('edit', '------').
  5858. $DSP->input_select_option('add_categories', $LANG->line('add_categories')).
  5859. $DSP->input_select_option('remove_categories', $LANG->line('remove_categories'));
  5860. // -------------------------------------------
  5861. // 'edit_entries_extra_actions' hook.
  5862. // - Add more options to the actions form at the bottom of the Edit screen
  5863. //
  5864. if ($EXT->active_hook('edit_entries_extra_actions') === TRUE)
  5865. {
  5866. $r .= $EXT->call_extension('edit_entries_extra_actions');
  5867. }
  5868. //
  5869. // -------------------------------------------
  5870. $r .= $DSP->input_select_footer();
  5871. }
  5872. else
  5873. {
  5874. $r .= $action;
  5875. }
  5876. $r .= $DSP->div_c();
  5877. $r .= $DSP->td_c().
  5878. $DSP->tr_c().
  5879. $DSP->table_c();
  5880. $r .= $DSP->form_close();
  5881. // Set output data
  5882. return $r;
  5883. }
  5884. /* END */
  5885. /** --------------------------------
  5886. /** Category Sub-tree
  5887. /** --------------------------------*/
  5888. function category_edit_subtree($cat_id, $categories, $depth)
  5889. {
  5890. global $DSP, $IN, $DB, $REGX, $LANG;
  5891. $spcr = '!-!';
  5892. $indent = $spcr.$spcr.$spcr.$spcr;
  5893. if ($depth == 1)
  5894. {
  5895. $depth = 4;
  5896. }
  5897. else
  5898. {
  5899. $indent = str_repeat($spcr, $depth).$indent;
  5900. $depth = $depth + 4;
  5901. }
  5902. $sel = '';
  5903. foreach ($categories as $key => $val)
  5904. {
  5905. if ($cat_id == $val['3'])
  5906. {
  5907. $pre = ($depth > 2) ? $spcr : '';
  5908. $this->cat_array[] = array($val['0'], $val['1'], $pre.$indent.$spcr.$val['2']);
  5909. $this->category_edit_subtree($val['1'], $categories, $depth);
  5910. }
  5911. }
  5912. }
  5913. /* END */
  5914. /** --------------------------------------------
  5915. /** JavaScript filtering code
  5916. /** --------------------------------------------*/
  5917. // This function writes some JavaScript functions that
  5918. // are used to switch the various pull-down menus in the
  5919. // EDIT page
  5920. //--------------------------------------------
  5921. function filtering_menus()
  5922. {
  5923. global $DSP, $LANG, $SESS, $FNS, $DB, $REGX, $PREFS;
  5924. // In order to build our filtering options we need to gather
  5925. // all the weblogs, categories and custom statuses
  5926. $blog_array = array();
  5927. $cat_array = array();
  5928. $status_array = array();
  5929. $allowed_blogs = $FNS->fetch_assigned_weblogs();
  5930. if (count($allowed_blogs) > 0)
  5931. {
  5932. // Fetch weblog titles
  5933. $sql = "SELECT blog_title, weblog_id, cat_group, status_group FROM exp_weblogs";
  5934. if ($SESS->userdata['group_id'] == 1)
  5935. {
  5936. $sql .= " WHERE weblog_id IN (";
  5937. foreach ($allowed_blogs as $val)
  5938. {
  5939. $sql .= "'".$val."',";
  5940. }
  5941. $sql = substr($sql, 0, -1).')';
  5942. }
  5943. else
  5944. {
  5945. $sql .= " WHERE is_user_blog = 'n'";
  5946. }
  5947. $sql .= " AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY blog_title";
  5948. $query = $DB->query($sql);
  5949. foreach ($query->result as $row)
  5950. {
  5951. $blog_array[$row['weblog_id']] = array($row['blog_title'], $row['cat_group'], $row['status_group']);
  5952. }
  5953. }
  5954. $order = ($this->nest_categories == 'y') ? 'group_id, parent_id, cat_name' : 'cat_name';
  5955. $query = $DB->query("SELECT cat_id, cat_name, group_id, parent_id FROM exp_categories WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY ".$order);
  5956. $categories = array();
  5957. if ($query->num_rows > 0)
  5958. {
  5959. foreach ($query->result as $row)
  5960. {
  5961. $categories[] = array($row['group_id'], $row['cat_id'], $REGX->entities_to_ascii($row['cat_name']), $row['parent_id']);
  5962. }
  5963. if ($this->nest_categories == 'y')
  5964. {
  5965. foreach($categories as $key => $val)
  5966. {
  5967. if (0 == $val['3'])
  5968. {
  5969. $this->cat_array[] = array($val['0'], $val['1'], $val['2']);
  5970. $this->category_edit_subtree($val['1'], $categories, $depth=1);
  5971. }
  5972. }
  5973. }
  5974. else
  5975. {
  5976. $this->cat_array = $categories;
  5977. }
  5978. }
  5979. $query = $DB->query("SELECT group_id, status FROM exp_statuses WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY status_order");
  5980. foreach ($query->result as $row)
  5981. {
  5982. $status_array[] = array($row['group_id'], $row['status']);
  5983. }
  5984. // Build the JavaScript needed for the dynamic pull-down menus
  5985. // We'll use output buffering since we'll need to return it
  5986. // and we break in and out of php
  5987. ob_start();
  5988. ?>
  5989. <script type="text/javascript">
  5990. <!--
  5991. var firstcategory = 1;
  5992. var firststatus = 1;
  5993. function changemenu(index)
  5994. {
  5995. var categories = new Array();
  5996. var statuses = new Array();
  5997. var i = firstcategory;
  5998. var j = firststatus;
  5999. var blogs = document.filterform.weblog_id.options[index].value;
  6000. with(document.filterform.cat_id)
  6001. {
  6002. if (blogs == "null")
  6003. {
  6004. categories[i] = new Option("<?php echo $LANG->line('all'); ?>", ""); i++;
  6005. categories[i] = new Option("<?php echo $LANG->line('none'); ?>", "none"); i++;
  6006. statuses[j] = new Option("<?php echo $LANG->line('all'); ?>", ""); j++;
  6007. statuses[j] = new Option("<?php echo $LANG->line('open'); ?>", "open"); j++;
  6008. statuses[j] = new Option("<?php echo $LANG->line('closed'); ?>", "closed"); j++;
  6009. }
  6010. <?php
  6011. foreach ($blog_array as $key => $val)
  6012. {
  6013. ?>
  6014. if (blogs == "<?php echo $key ?>")
  6015. {
  6016. categories[i] = new Option("<?php echo $LANG->line('all'); ?>", ""); i++;
  6017. categories[i] = new Option("<?php echo $LANG->line('none'); ?>", "none"); i++; <?php echo "\n";
  6018. if (count($this->cat_array) > 0)
  6019. {
  6020. $last_group = 0;
  6021. foreach ($this->cat_array as $k => $v)
  6022. {
  6023. if (in_array($v['0'], explode('|', $val['1'])))
  6024. {
  6025. if ($last_group == 0 OR $last_group != $v['0'])
  6026. {?>
  6027. categories[i] = new Option("-------", ""); i++; <?php echo "\n";
  6028. $last_group = $v['0'];
  6029. }
  6030. // Note: this kludgy indentation is so that the JavaScript will look nice when it's renedered on the page
  6031. ?>
  6032. categories[i] = new Option("<?php echo addslashes($v['2']);?>", "<?php echo $v['1'];?>"); i++; <?php echo "\n";
  6033. }
  6034. }
  6035. }
  6036. ?>
  6037. statuses[j] = new Option("<?php echo $LANG->line('all'); ?>", ""); j++;
  6038. <?php
  6039. if (count($status_array) > 0)
  6040. {
  6041. foreach ($status_array as $k => $v)
  6042. {
  6043. if ($v['0'] == $val['2'])
  6044. {
  6045. $status_name = ($v['1'] == 'closed' OR $v['1'] == 'open') ? $LANG->line($v['1']) : $v['1'];
  6046. ?>
  6047. statuses[j] = new Option("<?php echo $status_name; ?>", "<?php echo $v['1']; ?>"); j++; <?php
  6048. }
  6049. }
  6050. }
  6051. ?>
  6052. } // END if blogs
  6053. <?php
  6054. } // END OUTER FOREACH
  6055. ?>
  6056. spaceString = eval("/!-!/g");
  6057. with (document.filterform.cat_id)
  6058. {
  6059. for (i = length-1; i >= firstcategory; i--)
  6060. options[i] = null;
  6061. for (i = firstcategory; i < categories.length; i++)
  6062. {
  6063. options[i] = categories[i];
  6064. options[i].text = options[i].text.replace(spaceString, String.fromCharCode(160));
  6065. }
  6066. options[0].selected = true;
  6067. }
  6068. with (document.filterform.status)
  6069. {
  6070. for (i = length-1; i >= firststatus; i--)
  6071. options[i] = null;
  6072. for (i = firststatus;i < statuses.length; i++)
  6073. options[i] = statuses[i];
  6074. options[0].selected = true;
  6075. }
  6076. }
  6077. }
  6078. //--></script>
  6079. <?php
  6080. $javascript = ob_get_contents();
  6081. ob_end_clean();
  6082. return $javascript;
  6083. }
  6084. /* END */
  6085. /** --------------------------------------------
  6086. /** Multi Edit Form
  6087. /** --------------------------------------------*/
  6088. function multi_edit_form()
  6089. {
  6090. global $IN, $DB, $DSP, $LANG, $FNS, $SESS, $REGX, $LOC, $PREFS, $EXT;
  6091. if ( ! $DSP->allowed_group('can_access_edit'))
  6092. {
  6093. return $DSP->no_access_message();
  6094. }
  6095. // -------------------------------------------
  6096. // 'multi_edit_start' hook.
  6097. // - Allows complete control of the Multi Edit Form
  6098. // - Useful if someone adds an action to the Edit section actions select list
  6099. //
  6100. $edata = $EXT->call_extension('multi_edit_start');
  6101. if ($EXT->end_script === TRUE) return;
  6102. //
  6103. // -------------------------------------------
  6104. if ( ! in_array($IN->GBL('action', 'POST'), array('edit', 'delete', 'add_categories', 'remove_categories')))
  6105. {
  6106. return $DSP->no_access_message();
  6107. }
  6108. if ( ! $IN->GBL('toggle', 'POST'))
  6109. {
  6110. return $this->edit_entries();
  6111. }
  6112. if ($IN->GBL('action', 'POST') == 'delete')
  6113. {
  6114. return $this->delete_entries_confirm();
  6115. }
  6116. /** -----------------------------
  6117. /** Fetch the entry IDs
  6118. /** -----------------------------*/
  6119. $entry_ids = array();
  6120. foreach ($_POST as $key => $val)
  6121. {
  6122. if (strstr($key, 'toggle') AND ! is_array($val))
  6123. {
  6124. if ($val != '')
  6125. {
  6126. $entry_ids[] = $val;
  6127. }
  6128. }
  6129. }
  6130. // Are there still any entry IDs at this point?
  6131. // If not, we'll show an unauthorized message.
  6132. if (count($entry_ids) == 0)
  6133. {
  6134. return $DSP->no_access_message($LANG->line('unauthorized_to_edit'));
  6135. }
  6136. /** -----------------------------
  6137. /** Build and run the query
  6138. /** -----------------------------*/
  6139. $sql_top = "SELECT t.entry_id, t.weblog_id, t.author_id, t.title, t.url_title, t.entry_date, t.dst_enabled, t.status, t.allow_comments, t.allow_trackbacks, t.sticky, w.comment_system_enabled, w.show_options_cluster
  6140. FROM exp_weblog_titles AS t, exp_weblogs AS w
  6141. WHERE t.entry_id IN (";
  6142. $sql = '';
  6143. foreach ($entry_ids as $id)
  6144. {
  6145. $sql .= $id.',';
  6146. }
  6147. $sql = substr($sql, 0, -1).') ';
  6148. $sql .= "AND t.weblog_id = w.weblog_id ORDER BY entry_date desc";
  6149. $query = $DB->query($sql_top.$sql);
  6150. /** -----------------------------
  6151. /** Security check...
  6152. /** -----------------------------*/
  6153. // Before we show anything we have to make sure that the user is allowed to
  6154. // access the blog the entry is in, and if the user is trying
  6155. // to edit an entry authored by someone else they are allowed to
  6156. $disallowed_ids = array();
  6157. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  6158. foreach ($query->result as $row)
  6159. {
  6160. if ( ! in_array($row['weblog_id'], $assigned_weblogs))
  6161. {
  6162. $disallowed_ids = $row['entry_id'];
  6163. }
  6164. if ($row['author_id'] != $SESS->userdata('member_id'))
  6165. {
  6166. if ( ! $DSP->allowed_group('can_edit_other_entries'))
  6167. {
  6168. $disallowed_ids = $row['entry_id'];
  6169. }
  6170. }
  6171. if (count($disallowed_ids) > 0)
  6172. {
  6173. $disallowed_ids = array_unique($disallowed_ids);
  6174. }
  6175. }
  6176. /** -----------------------------
  6177. /** Are there disallowed posts?
  6178. /** -----------------------------*/
  6179. // If so, we have to remove them....
  6180. if (count($disallowed_ids) > 0)
  6181. {
  6182. $new_ids = array_diff($entry_ids, $disallowed_ids);
  6183. // After removing the disallowed entry IDs are there any left?
  6184. if (count($new_ids) == 0)
  6185. {
  6186. return $DSP->no_access_message($LANG->line('unauthorized_to_edit'));
  6187. }
  6188. // Run the query one more time with the proper IDs.
  6189. $sql = '';
  6190. foreach ($new_ids as $id)
  6191. {
  6192. $sql .= $id.',';
  6193. }
  6194. unset($query);
  6195. $sql = substr($sql, 0, -1).') ';
  6196. $sql .= "ORDER BY entry_date desc";
  6197. $query = $DB->query($sql_top.$sql);
  6198. }
  6199. /** -----------------------------
  6200. /** Adding/Removing of Categories Breaks Off to Their Own Function
  6201. /** -----------------------------*/
  6202. if ($IN->GBL('action', 'POST') == 'add_categories')
  6203. {
  6204. return $this->multi_categories_edit('add', $query);
  6205. }
  6206. elseif ($IN->GBL('action', 'POST') == 'remove_categories')
  6207. {
  6208. return $this->multi_categories_edit('remove', $query);
  6209. }
  6210. /** -----------------------------
  6211. /** Fetch the weblog preferences
  6212. /** -----------------------------*/
  6213. // We need these in order to fetch the status groups and options.
  6214. $sql = "SELECT weblog_id, status_group, deft_status FROM exp_weblogs WHERE weblog_id IN(";
  6215. $weblog_ids = array();
  6216. foreach ($query->result as $row)
  6217. {
  6218. $weblog_ids[] = $row['weblog_id'];
  6219. $sql .= $row['weblog_id'].',';
  6220. }
  6221. $weblog_query = $DB->query(substr($sql, 0, -1).')');
  6222. /** --------------------------------
  6223. /** Fetch disallowed statuses
  6224. /** --------------------------------*/
  6225. $no_status_access = array();
  6226. if ($SESS->userdata['group_id'] != 1)
  6227. {
  6228. $result = $DB->query("SELECT status_id FROM exp_status_no_access WHERE member_group = '".$SESS->userdata('group_id')."'");
  6229. if ($result->num_rows > 0)
  6230. {
  6231. foreach ($result->result as $row)
  6232. {
  6233. $no_status_access[] = $row['status_id'];
  6234. }
  6235. }
  6236. }
  6237. /** -----------------------------
  6238. /** Build the output
  6239. /** -----------------------------*/
  6240. $r = $DSP->form_open(array('action' => 'C=edit'.AMP.'M=update_multi_entries'));
  6241. $r .= '<div class="tableHeading">'.$LANG->line('multi_entry_editor').'</div>';
  6242. if (isset($_POST['pageurl']))
  6243. {
  6244. $r .= $DSP->input_hidden('redirect', $REGX->xss_clean($_POST['pageurl']));
  6245. }
  6246. foreach ($query->result as $row)
  6247. {
  6248. $r .= $DSP->input_hidden('entry_id['.$row['entry_id'].']', $row['entry_id']);
  6249. $r .= $DSP->input_hidden('weblog_id['.$row['entry_id'].']', $row['weblog_id']);
  6250. if ($PREFS->ini('honor_entry_dst') == 'y')
  6251. {
  6252. $r .= $DSP->input_hidden('dst_enabled['.$row['entry_id'].']', $row['dst_enabled']);
  6253. }
  6254. $r .= NL.'<div class="publishTabWrapper">';
  6255. $r .= NL.'<div class="publishBox">';
  6256. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  6257. $r .= NL.'<td class="publishItemWrapper" valign="top" style="width:45%;">'.BR;
  6258. $r .= $DSP->div('clusterLineR');
  6259. $r .= $DSP->heading($LANG->line('title'), 5).
  6260. $DSP->input_text('title['.$row['entry_id'].']', $row['title'], '20', '100', 'input', '95%', 'onkeyup="liveUrlTitle();"');
  6261. $r .= $DSP->qdiv('defaultSmall', NBS);
  6262. $r .= $DSP->heading($LANG->line('url_title'), 5).
  6263. $DSP->input_text('url_title['.$row['entry_id'].']', $row['url_title'], '20', '75', 'input', '95%');
  6264. $r .= $DSP->div_c();
  6265. $r .= '</td>';
  6266. /** --------------------------------
  6267. /** Status pull-down menu
  6268. /** --------------------------------*/
  6269. $status_queries = array();
  6270. $status_menu = '';
  6271. foreach ($weblog_query->result as $weblog_row)
  6272. {
  6273. if ($weblog_row['weblog_id'] != $row['weblog_id'])
  6274. continue;
  6275. $status_query = $DB->query("SELECT * FROM exp_statuses WHERE group_id = '".$weblog_row['status_group']."' order by status_order");
  6276. $menu_status = '';
  6277. if ($status_query->num_rows == 0)
  6278. {
  6279. $menu_status .= $DSP->input_select_option('open', $LANG->line('open'), ($row['status'] == 'open') ? 1 : '');
  6280. $menu_status .= $DSP->input_select_option('closed', $LANG->line('closed'), ($row['status'] == 'closed') ? 1 : '');
  6281. }
  6282. else
  6283. {
  6284. $no_status_flag = TRUE;
  6285. foreach ($status_query->result as $status_row)
  6286. {
  6287. $selected = ($row['status'] == $status_row['status']) ? 1 : '';
  6288. if (in_array($status_row['status_id'], $no_status_access))
  6289. {
  6290. continue;
  6291. }
  6292. $no_status_flag = FALSE;
  6293. $status_name = ($status_row['status'] == 'open' OR $status_row['status'] == 'closed') ? $LANG->line($status_row['status']) : $REGX->form_prep($status_row['status']);
  6294. $menu_status .= $DSP->input_select_option($REGX->form_prep($status_row['status']), $status_name, $selected);
  6295. }
  6296. /** --------------------------------
  6297. /** Were there no statuses?
  6298. /** --------------------------------*/
  6299. // If the current user is not allowed to submit any statuses
  6300. // we'll set the default to closed
  6301. if ($no_status_flag == TRUE)
  6302. {
  6303. $menu_status .= $DSP->input_select_option('closed', $LANG->line('closed'));
  6304. }
  6305. }
  6306. $status_menu = $menu_status;
  6307. }
  6308. $r .= NL.'<td class="publishItemWrapper" valign="top" style="width:25%;">'.BR;
  6309. $r .= $DSP->div('clusterLineR');
  6310. $r .= $DSP->heading($LANG->line('entry_status'), 5);
  6311. $r .= $DSP->input_select_header('status['.$row['entry_id'].']');
  6312. $r .= $status_menu;
  6313. $r .= $DSP->input_select_footer();
  6314. $r .= $DSP->div('itemWrapperTop');
  6315. $r .= $DSP->heading($LANG->line('entry_date'), 5);
  6316. $r .= $DSP->input_text('entry_date['.$row['entry_id'].']', $LOC->set_human_time($row['entry_date']), '18', '23', 'input', '150px');
  6317. $r .= $DSP->div_c();
  6318. $r .= $DSP->div_c();
  6319. $r .= '</td>';
  6320. $r .= NL.'<td class="publishItemWrapper" valign="top" style="width:30%;">'.BR;
  6321. if ($row['show_options_cluster'] == 'n')
  6322. {
  6323. $r .= $DSP->input_hidden('sticky['.$row['entry_id'].']', $row['sticky']);
  6324. }
  6325. else
  6326. {
  6327. $r .= $DSP->heading(NBS.$LANG->line('options'), 5);
  6328. $r .= $DSP->qdiv('publishPad', $DSP->input_checkbox('sticky['.$row['entry_id'].']', 'y', $row['sticky']).' '.$LANG->line('sticky'));
  6329. }
  6330. if ( ! isset($this->installed_modules['comment']) OR $row['comment_system_enabled'] == 'n' OR $row['show_options_cluster'] == 'n')
  6331. {
  6332. $r .= $DSP->input_hidden('allow_comments['.$row['entry_id'].']', $row['allow_comments']);
  6333. }
  6334. else
  6335. {
  6336. $r .= $DSP->qdiv('publishPad', $DSP->input_checkbox('allow_comments['.$row['entry_id'].']', 'y', $row['allow_comments']).' '.$LANG->line('allow_comments'));
  6337. }
  6338. if ( ! isset($this->installed_modules['trackback']) OR $row['show_options_cluster'] == 'n')
  6339. {
  6340. $r .= $DSP->input_hidden('allow_trackbacks['.$row['entry_id'].']', $row['allow_trackbacks']);
  6341. }
  6342. else
  6343. {
  6344. $r .= $DSP->qdiv('publishPad', $DSP->input_checkbox('allow_trackbacks['.$row['entry_id'].']', 'y', $row['allow_trackbacks']).' '.$LANG->line('allow_trackbacks'));
  6345. }
  6346. $r .= '</td>';
  6347. $r .= "</tr></table>";
  6348. $r .= $DSP->div_c();
  6349. $r .= $DSP->div_c();
  6350. }
  6351. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update'))).
  6352. $DSP->form_close();
  6353. $DSP->title = $LANG->line('multi_entry_editor');
  6354. $DSP->crumb = $LANG->line('multi_entry_editor');
  6355. $DSP->body = $r;
  6356. }
  6357. /* END */
  6358. /** -----------------------------------------
  6359. /** Update Multi Entries
  6360. /** -----------------------------------------*/
  6361. function update_multi_entries()
  6362. {
  6363. global $DSP, $DB, $LANG, $REGX, $FNS, $LOC, $PREFS, $SESS;
  6364. if ( ! $DSP->allowed_group('can_access_edit'))
  6365. {
  6366. return $DSP->no_access_message();
  6367. }
  6368. if ( ! is_array($_POST['entry_id']))
  6369. {
  6370. return $DSP->no_access_message();
  6371. }
  6372. $LANG->fetch_language_file('publish_ad');
  6373. foreach ($_POST['entry_id'] as $id)
  6374. {
  6375. $weblog_id = $_POST['weblog_id'][$id];
  6376. $data = array(
  6377. 'title' => strip_tags($_POST['title'][$id]),
  6378. 'url_title' => $_POST['url_title'][$id],
  6379. 'entry_date' => $_POST['entry_date'][$id],
  6380. 'status' => $_POST['status'][$id],
  6381. 'sticky' => (isset($_POST['sticky'][$id]) AND $_POST['sticky'][$id] == 'y') ? 'y' : 'n',
  6382. 'allow_comments' => (isset($_POST['allow_comments'][$id]) AND $_POST['allow_comments'][$id] == 'y') ? 'y' : 'n',
  6383. 'allow_trackbacks' => (isset($_POST['allow_trackbacks'][$id]) AND $_POST['allow_trackbacks'][$id] == 'y') ? 'y' : 'n'
  6384. );
  6385. $error = array();
  6386. /** ---------------------------------
  6387. /** No entry title? Assign error.
  6388. /** ---------------------------------*/
  6389. if ($data['title'] == "")
  6390. {
  6391. $error[] = $LANG->line('missing_title');
  6392. }
  6393. /** --------------------------------------
  6394. /** Is the title unique?
  6395. /** --------------------------------------*/
  6396. if ($data['title'] != '')
  6397. {
  6398. /** ---------------------------------
  6399. /** Do we have a URL title?
  6400. /** ---------------------------------*/
  6401. // If not, create one from the title
  6402. if ($data['url_title'] == '')
  6403. {
  6404. $data['url_title'] = $REGX->create_url_title($data['title'], TRUE);
  6405. }
  6406. // Kill all the extraneous characters.
  6407. // We want the URL title to pure alpha text
  6408. $data['url_title'] = $REGX->create_url_title($data['url_title']);
  6409. // Is the url_title a pure number? If so we show an error.
  6410. if (is_numeric($data['url_title']))
  6411. {
  6412. $error[] = $LANG->line('url_title_is_numeric');
  6413. }
  6414. /** ---------------------------------
  6415. /** Is URL title unique?
  6416. /** ---------------------------------*/
  6417. $unique = FALSE;
  6418. $i = 0;
  6419. while ($unique == FALSE)
  6420. {
  6421. $temp = ($i == 0) ? $data['url_title'] : $data['url_title'].$i;
  6422. $i++;
  6423. $sql = "SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title = '".$DB->escape_str($temp)."' AND weblog_id = '".$DB->escape_str($weblog_id)."'";
  6424. if ($id != '')
  6425. {
  6426. $sql .= " AND entry_id != '".$DB->escape_str($id)."'";
  6427. }
  6428. $query = $DB->query($sql);
  6429. if ($query->row['count'] == 0)
  6430. {
  6431. $unique = TRUE;
  6432. }
  6433. // Safety
  6434. if ($i >= 50)
  6435. {
  6436. $error[] = $LANG->line('url_title_not_unique');
  6437. break;
  6438. }
  6439. }
  6440. $data['url_title'] = $temp;
  6441. }
  6442. /** ---------------------------------------------
  6443. /** No date? Assign error.
  6444. /** ---------------------------------------------*/
  6445. if ($data['entry_date'] == '')
  6446. {
  6447. $error[] = $LANG->line('missing_date');
  6448. }
  6449. /** ---------------------------------------------
  6450. /** Convert the date to a Unix timestamp
  6451. /** ---------------------------------------------*/
  6452. $data['entry_date'] = $LOC->convert_human_date_to_gmt($data['entry_date']);
  6453. if ( ! is_numeric($data['entry_date']))
  6454. {
  6455. // Localize::convert_human_date_to_gmt() returns verbose errors
  6456. if ($data['entry_date'] !== FALSE)
  6457. {
  6458. $error[] = $data['entry_date'];
  6459. }
  6460. else
  6461. {
  6462. $error[] = $LANG->line('invalid_date_formatting');
  6463. }
  6464. }
  6465. /** ---------------------------------
  6466. /** Do we have an error to display?
  6467. /** ---------------------------------*/
  6468. if (count($error) > 0)
  6469. {
  6470. $msg = '';
  6471. foreach($error as $val)
  6472. {
  6473. $msg .= $DSP->qdiv('itemWrapper', $val);
  6474. }
  6475. return $DSP->error_message($msg);
  6476. }
  6477. /** ---------------------------------
  6478. /** Day, Month, and Year Fields
  6479. /** ---------------------------------*/
  6480. $data['year'] = date('Y', $data['entry_date']);
  6481. $data['month'] = date('m', $data['entry_date']);
  6482. $data['day'] = date('d', $data['entry_date']);
  6483. /** ---------------------------------
  6484. /** Update the entry
  6485. /** ---------------------------------*/
  6486. $DB->query($DB->update_string('exp_weblog_titles', $data, "entry_id = '$id'"));
  6487. }
  6488. /** ---------------------------------
  6489. /** Clear caches if needed
  6490. /** ---------------------------------*/
  6491. $entry_ids = "'";
  6492. foreach($_POST['entry_id'] as $id)
  6493. {
  6494. $entry_ids .= $DB->escape_str($id)."', '";
  6495. }
  6496. $entry_ids = substr($entry_ids, 0, -3);
  6497. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_relationships
  6498. WHERE rel_parent_id IN ({$entry_ids})
  6499. OR rel_child_id IN ({$entry_ids})");
  6500. $clear_rel = ($query->row['count'] > 0) ? TRUE : FALSE;
  6501. if ($PREFS->ini('new_posts_clear_caches') == 'y')
  6502. {
  6503. $FNS->clear_caching('all', '', $clear_rel);
  6504. }
  6505. else
  6506. {
  6507. $FNS->clear_caching('sql', '', $clear_rel);
  6508. }
  6509. if (isset($_POST['redirect']) && ($redirect = base64_decode($REGX->xss_clean($_POST['redirect']))) !== FALSE)
  6510. {
  6511. $FNS->redirect($REGX->xss_clean($redirect));
  6512. }
  6513. else
  6514. {
  6515. $FNS->redirect(BASE.AMP.'C=edit'.AMP.'U=mu');
  6516. }
  6517. exit;
  6518. }
  6519. /* END */
  6520. /** --------------------------------------------
  6521. /** Multi Categories Edit Form
  6522. /** --------------------------------------------*/
  6523. function multi_categories_edit($type, $query)
  6524. {
  6525. global $IN, $DB, $DSP, $LANG, $OUT;
  6526. if ( ! $DSP->allowed_group('can_access_edit'))
  6527. {
  6528. return $DSP->no_access_message();
  6529. }
  6530. if ($query->num_rows == 0)
  6531. {
  6532. return $DSP->no_access_message($LANG->line('unauthorized_to_edit'));
  6533. }
  6534. /** -----------------------------
  6535. /** Fetch the cat_group
  6536. /** -----------------------------*/
  6537. /* Available from $query: entry_id, weblog_id, author_id, title, url_title,
  6538. entry_date, dst_enabled, status, allow_comments,
  6539. allow_trackbacks, sticky
  6540. */
  6541. $sql = "SELECT DISTINCT cat_group FROM exp_weblogs WHERE weblog_id IN(";
  6542. $weblog_ids = array();
  6543. $entry_ids = array();
  6544. foreach ($query->result as $row)
  6545. {
  6546. $weblog_ids[] = $row['weblog_id'];
  6547. $entry_ids[] = $row['entry_id'];
  6548. $sql .= $row['weblog_id'].',';
  6549. }
  6550. $group_query = $DB->query(substr($sql, 0, -1).')');
  6551. $valid = 'n';
  6552. if ($group_query->num_rows > 0)
  6553. {
  6554. $valid = 'y';
  6555. $last = explode('|', $group_query->row['cat_group']);
  6556. foreach($group_query->result as $row)
  6557. {
  6558. $valid_cats = array_intersect($last, explode('|', $row['cat_group']));
  6559. if (sizeof($valid_cats) == 0)
  6560. {
  6561. $valid = 'n';
  6562. break;
  6563. }
  6564. }
  6565. }
  6566. if ($valid == 'n')
  6567. {
  6568. return $OUT->show_user_error('submission', $LANG->line('no_category_group_match'));
  6569. }
  6570. $this->category_tree(($cat_group = implode('|', $valid_cats)));
  6571. if (count($this->categories) == 0)
  6572. {
  6573. $cats = $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_categories')), 'categorytree');
  6574. }
  6575. else
  6576. {
  6577. $cats = "<div id='categorytree'>";
  6578. foreach ($this->categories as $val)
  6579. {
  6580. $cats .= $val;
  6581. }
  6582. $cats .= '</div>';
  6583. }
  6584. if ($DSP->allowed_group('can_admin_weblogs') OR $DSP->allowed_group('can_edit_categories'))
  6585. {
  6586. $cats .= '<div id="cateditlink" style="padding:0; margin:0;display:none;">';
  6587. if (stristr($cat_group, '|'))
  6588. {
  6589. $catg_query = $DB->query("SELECT group_name, group_id FROM exp_category_groups WHERE group_id IN ('".str_replace('|', "','", $DB->escape_str($cat_group))."')");
  6590. $links = '';
  6591. foreach($catg_query->result as $catg_row)
  6592. {
  6593. $links .= $DSP->anchorpop(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$catg_row['group_id'].AMP.'cat_group='.$cat_group.AMP.'Z=1', '<b>'.$catg_row['group_name'].'</b>').', ';
  6594. }
  6595. $cats .= $DSP->qdiv('itemWrapper', '<b>'.$LANG->line('edit_categories').': </b>'.substr($links, 0, -2), '750');
  6596. }
  6597. else
  6598. {
  6599. $cats .= $DSP->qdiv('itemWrapper', $DSP->anchorpop(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$cat_group.AMP.'Z=1', '<b>'.$LANG->line('edit_categories').'</b>', '750'));
  6600. }
  6601. $cats .= '</div>';
  6602. }
  6603. /** -----------------------------
  6604. /** Build the output
  6605. /** -----------------------------*/
  6606. $r = $DSP->form_open(
  6607. array(
  6608. 'action' => 'C=edit'.AMP.'M=entry_category_update',
  6609. 'name' => 'entryform',
  6610. 'id' => 'entryform'
  6611. ),
  6612. array(
  6613. 'entry_ids' => implode('|', $entry_ids),
  6614. 'type' => ($type == 'add') ? 'add' : 'remove'
  6615. )
  6616. );
  6617. $r .= <<<EOT
  6618. <script type="text/javascript">
  6619. <!--
  6620. /** ------------------------------------
  6621. /** Swap out categories
  6622. /** -------------------------------------*/
  6623. // This is used by the "edit categories" feature
  6624. function set_catlink()
  6625. {
  6626. if (document.getElementById('cateditlink'))
  6627. {
  6628. if (browser == "IE" && OS == "Mac")
  6629. {
  6630. document.getElementById('cateditlink').style.display = "none";
  6631. }
  6632. else
  6633. {
  6634. document.getElementById('cateditlink').style.display = "block";
  6635. }
  6636. }
  6637. }
  6638. function swap_categories(str)
  6639. {
  6640. document.getElementById('categorytree').innerHTML = str;
  6641. }
  6642. -->
  6643. </script>
  6644. EOT;
  6645. $r .= '<div class="tableHeading">'.$LANG->line('multi_entry_category_editor').'</div>';
  6646. $r .= NL.'<div class="publishTabWrapper">';
  6647. $r .= NL.'<div class="publishBox">';
  6648. $r .= $DSP->heading(($type == 'add') ? $LANG->line('add_categories') : $LANG->line('remove_categories'), 5);
  6649. $r .= NL."<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' style='width:99%'><tr>";
  6650. $r .= NL.'<td class="publishItemWrapper" valign="top" style="width:45%;">'.BR;
  6651. $r .= $cats;
  6652. $r .= '</td>';
  6653. $r .= "</tr></table>";
  6654. $r .= $DSP->div_c();
  6655. $r .= $DSP->div_c();
  6656. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update'))).
  6657. $DSP->form_close();
  6658. $DSP->body_props .= ' onload="set_catlink();" ';
  6659. $DSP->title = $LANG->line('multi_entry_category_editor');
  6660. $DSP->crumb = $LANG->line('multi_entry_category_editor');
  6661. $DSP->body = $r;
  6662. }
  6663. /* END */
  6664. /** --------------------------------------------
  6665. /** Update Multiple Entries with Categories
  6666. /** --------------------------------------------*/
  6667. function multi_entry_category_update()
  6668. {
  6669. global $IN, $DB, $DSP, $LANG, $PREFS, $FNS, $OUT;
  6670. if ( ! $DSP->allowed_group('can_access_edit'))
  6671. {
  6672. return $DSP->no_access_message();
  6673. }
  6674. if ($IN->GBL('entry_ids') === FALSE OR $IN->GBL('type') === FALSE)
  6675. {
  6676. return $DSP->no_access_message($LANG->line('unauthorized_to_edit'));
  6677. }
  6678. if ($IN->GBL('category') === FALSE OR ! is_array($_POST['category']) OR sizeof($_POST['category']) == 0)
  6679. {
  6680. return $OUT->show_user_error('submission', $LANG->line('no_categories_selected'));
  6681. }
  6682. /** ---------------------------------
  6683. /** Fetch categories
  6684. /** ---------------------------------*/
  6685. // We do this first so we can destroy the category index from
  6686. // the $_POST array since we use a separate table to store categories in
  6687. foreach ($_POST['category'] as $cat_id)
  6688. {
  6689. $this->cat_parents[] = $cat_id;
  6690. }
  6691. if ($this->assign_cat_parent == TRUE)
  6692. {
  6693. $this->fetch_category_parents($_POST['category']);
  6694. }
  6695. $this->cat_parents = array_unique($this->cat_parents);
  6696. sort($this->cat_parents);
  6697. unset($_POST['category']);
  6698. $ids = array();
  6699. foreach (explode('|', $_POST['entry_ids']) as $entry_id)
  6700. {
  6701. $ids[] = $DB->escape_str($entry_id);
  6702. }
  6703. unset($_POST['entry_ids']);
  6704. $entries_string = implode("','", $ids);
  6705. /** -----------------------------
  6706. /** Get Category Group IDs
  6707. /** -----------------------------*/
  6708. $query = $DB->query("SELECT DISTINCT exp_weblogs.cat_group FROM exp_weblogs, exp_weblog_titles
  6709. WHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  6710. AND exp_weblog_titles.entry_id IN ('".$entries_string."')");
  6711. $valid = 'n';
  6712. if ($query->num_rows > 0)
  6713. {
  6714. $valid = 'y';
  6715. $last = explode('|', $query->row['cat_group']);
  6716. foreach($query->result as $row)
  6717. {
  6718. $valid_cats = array_intersect($last, explode('|', $row['cat_group']));
  6719. if (sizeof($valid_cats) == 0)
  6720. {
  6721. $valid = 'n';
  6722. break;
  6723. }
  6724. }
  6725. }
  6726. if ($valid == 'n')
  6727. {
  6728. return $DSP->show_user_error($LANG->line('no_category_group_match'));
  6729. }
  6730. /** -----------------------------
  6731. /** Remove Valid Cats, Then Add...
  6732. /** -----------------------------*/
  6733. $query = $DB->query("SELECT cat_id FROM exp_categories
  6734. WHERE group_id IN ('".implode("','", $valid_cats)."')
  6735. AND cat_id IN ('".implode("','", $this->cat_parents)."')");
  6736. $valid_cat_ids = array();
  6737. if ($query->num_rows > 0)
  6738. {
  6739. foreach($query->result as $row)
  6740. {
  6741. $DB->query("DELETE FROM exp_category_posts WHERE cat_id = ".$row['cat_id']." AND entry_id IN ('".$entries_string."')");
  6742. $valid_cat_ids[] = $row['cat_id'];
  6743. }
  6744. }
  6745. if ($IN->GBL('type') == 'add')
  6746. {
  6747. $insert_cats = array_intersect($this->cat_parents, $valid_cat_ids);
  6748. // How brutish...
  6749. foreach($ids as $id)
  6750. {
  6751. foreach($insert_cats as $val)
  6752. {
  6753. $DB->query($DB->insert_string('exp_category_posts', array('entry_id' => $id, 'cat_id' => $val)));
  6754. }
  6755. }
  6756. }
  6757. /** ---------------------------------
  6758. /** Clear caches if needed
  6759. /** ---------------------------------*/
  6760. if ($PREFS->ini('new_posts_clear_caches') == 'y')
  6761. {
  6762. $FNS->clear_caching('all');
  6763. }
  6764. else
  6765. {
  6766. $FNS->clear_caching('sql');
  6767. }
  6768. return $this->edit_entries('', $DSP->qdiv('success', $LANG->line('multi_entries_updated')));
  6769. }
  6770. /* END */
  6771. /** --------------------------------------------
  6772. /** View weblog entry
  6773. /** --------------------------------------------*/
  6774. // This function displays an individual weblog entry
  6775. //--------------------------------------------
  6776. function view_entry()
  6777. {
  6778. global $DSP, $LANG, $FNS, $DB, $IN, $REGX, $SESS, $EXT, $LOC, $PREFS;
  6779. // -------------------------------------------
  6780. // 'view_entry_start' hook.
  6781. // - Allows complete rewrite of View Entry page.
  6782. //
  6783. $edata = $EXT->call_extension('view_entry_start');
  6784. if ($EXT->end_script === TRUE) return;
  6785. //
  6786. // -------------------------------------------
  6787. if ( ! $entry_id = $IN->GBL('entry_id', 'GET'))
  6788. {
  6789. return false;
  6790. }
  6791. if ( ! $weblog_id = $IN->GBL('weblog_id', 'GET'))
  6792. {
  6793. return false;
  6794. }
  6795. $assigned_weblogs = $FNS->fetch_assigned_weblogs();
  6796. if ( ! in_array($weblog_id, $assigned_weblogs))
  6797. {
  6798. return $DSP->no_access_message($LANG->line('unauthorized_for_this_blog'));
  6799. }
  6800. /** ----------------------------------------
  6801. /** Instantiate Typography class
  6802. /** ----------------------------------------*/
  6803. if ( ! class_exists('Typography'))
  6804. {
  6805. require PATH_CORE.'core.typography'.EXT;
  6806. }
  6807. $TYPE = new Typography;
  6808. $TYPE->convert_curly = FALSE;
  6809. $query = $DB->query("SELECT weblog_html_formatting, weblog_allow_img_urls, weblog_auto_link_urls from exp_weblogs WHERE weblog_id = '$weblog_id'");
  6810. if ($query->num_rows > 0)
  6811. {
  6812. foreach ($query->row as $key => $val)
  6813. {
  6814. $$key = $val;
  6815. }
  6816. }
  6817. $message = '';
  6818. if ($U = $IN->GBL('U'))
  6819. {
  6820. $message = ($U == 'new') ? $DSP->qdiv('success', $LANG->line('entry_has_been_added')) : $DSP->qdiv('success', $LANG->line('entry_has_been_updated'));
  6821. }
  6822. $query = $DB->query("SELECT field_group FROM exp_weblogs WHERE weblog_id = '$weblog_id'");
  6823. if ($query->num_rows == 0)
  6824. {
  6825. return false;
  6826. }
  6827. $field_group = $query->row['field_group'];
  6828. $query = $DB->query("SELECT field_id, field_type FROM exp_weblog_fields WHERE group_id = '$field_group' ORDER BY field_order");
  6829. $fields = array();
  6830. foreach ($query->result as $row)
  6831. {
  6832. $fields['field_id_'.$row['field_id']] = $row['field_type'];
  6833. }
  6834. $sql = "SELECT exp_weblog_titles.*, exp_weblog_data.*, exp_weblogs.*
  6835. FROM exp_weblog_titles, exp_weblog_data, exp_weblogs
  6836. WHERE exp_weblog_titles.entry_id = '$entry_id'
  6837. AND exp_weblog_titles.entry_id = exp_weblog_data.entry_id
  6838. AND exp_weblogs.weblog_id = exp_weblog_titles.weblog_id";
  6839. $result = $DB->query($sql);
  6840. $show_edit_link = TRUE;
  6841. $show_comments_link = TRUE;
  6842. if ($result->row['author_id'] != $SESS->userdata('member_id'))
  6843. {
  6844. if ( ! $DSP->allowed_group('can_view_other_entries'))
  6845. {
  6846. return $DSP->no_access_message();
  6847. }
  6848. if ( ! $DSP->allowed_group('can_edit_other_entries'))
  6849. {
  6850. $show_edit_link = FALSE;
  6851. }
  6852. if ( ! $DSP->allowed_group('can_view_other_comments') AND
  6853. ! $DSP->allowed_group('can_delete_all_comments') AND
  6854. ! $DSP->allowed_group('can_moderate_comments'))
  6855. {
  6856. $show_comments_link = FALSE;
  6857. }
  6858. }
  6859. else
  6860. {
  6861. if ( ! $DSP->allowed_group('can_edit_own_comments') AND
  6862. ! $DSP->allowed_group('can_delete_own_comments') AND
  6863. ! $DSP->allowed_group('can_moderate_comments'))
  6864. {
  6865. $show_comments_link = FALSE;
  6866. }
  6867. }
  6868. $r = '';
  6869. if ($message != '')
  6870. $r .= $DSP->qdiv('box', $message);
  6871. if ($result->num_rows > 0)
  6872. {
  6873. $r .= $DSP->qdiv('tableHeading', stripslashes($result->row['title']));
  6874. $r .= $DSP->div('box');
  6875. foreach ($fields as $key => $val)
  6876. {
  6877. if (isset($result->row[$key]) AND $val != 'rel' and $result->row[$key] != '')
  6878. {
  6879. $expl = explode('field_id_', $key);
  6880. if (isset($result->row['field_dt_'.$expl['1']]))
  6881. {
  6882. if ($result->row[$key] > 0)
  6883. {
  6884. $localize = TRUE;
  6885. $date = $result->row[$key];
  6886. if ($result->row['field_dt_'.$expl['1']] != '')
  6887. {
  6888. $date = $LOC->offset_entry_dst($date, $result->row['dst_enabled']);
  6889. $date = $LOC->simpl_offset($date, $result->row['field_dt_'.$expl['1']]);
  6890. $localize = FALSE;
  6891. }
  6892. $r .= $LOC->set_human_time($date, $localize);
  6893. }
  6894. }
  6895. else
  6896. {
  6897. $r .= $TYPE->parse_type( stripslashes($result->row[$key]),
  6898. array(
  6899. 'text_format' => $result->row['field_ft_'.$expl['1']],
  6900. 'html_format' => $weblog_html_formatting,
  6901. 'auto_links' => $weblog_auto_link_urls,
  6902. 'allow_img_url' => $weblog_allow_img_urls,
  6903. )
  6904. );
  6905. }
  6906. }
  6907. }
  6908. $r .= $DSP->div_c();
  6909. }
  6910. if ($show_edit_link)
  6911. {
  6912. $r .= $DSP->qdiv('itemWrapperTop', $DSP->qdiv('defaultBold', $DSP->anchor(
  6913. BASE.AMP.'C=edit'.AMP.'M=edit_entry'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id,
  6914. $LANG->line('edit_this_entry')
  6915. )));
  6916. }
  6917. if ($show_comments_link)
  6918. {
  6919. if (isset($this->installed_modules['comment']))
  6920. {
  6921. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$entry_id."'");$DB->q_count--;
  6922. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $DSP->anchor(
  6923. BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id,
  6924. $LANG->line('view_comments').NBS.'('.$res->row['count'].')'
  6925. )));
  6926. }
  6927. if ( isset($this->installed_modules['trackback']))
  6928. {
  6929. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_trackbacks WHERE entry_id = '".$entry_id."'");$DB->q_count--;
  6930. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $DSP->anchor(
  6931. BASE.AMP.'C=edit'.AMP.'M=view_trackbacks'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id,
  6932. $LANG->line('view_trackbacks').NBS.'('.$res->row['count'].')'
  6933. )));
  6934. }
  6935. }
  6936. if ($result->row['live_look_template'] != 0)
  6937. {
  6938. $res = $DB->query("SELECT exp_template_groups.group_name, exp_templates.template_name
  6939. FROM exp_template_groups, exp_templates
  6940. WHERE exp_template_groups.group_id = exp_templates.group_id
  6941. AND exp_templates.template_id = '".$DB->escape_str($result->row['live_look_template'])."'");
  6942. if ($res->num_rows == 1)
  6943. {
  6944. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  6945. $r .= $DSP->qdiv('itemWrapper',
  6946. $DSP->qdiv('defaultBold',
  6947. $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.
  6948. $FNS->create_url($res->row['group_name'].'/'.$res->row['template_name'].'/'.$entry_id),
  6949. $LANG->line('live_look'), '', TRUE)
  6950. )
  6951. );
  6952. }
  6953. }
  6954. // -------------------------------------------
  6955. // 'view_entry_end' hook.
  6956. // - Add content to end of view entry page
  6957. // - Added: 1.4.1
  6958. //
  6959. if ($EXT->active_hook('view_entry_end') === TRUE)
  6960. {
  6961. $r .= $EXT->call_extension('view_entry_end', $entry_id);
  6962. }
  6963. //
  6964. // -------------------------------------------
  6965. $DSP->set_return_data(
  6966. $LANG->line('view_entry'),
  6967. $r,
  6968. $LANG->line('view_entry')
  6969. );
  6970. }
  6971. /* END */
  6972. /** --------------------------------------------
  6973. /** Delete Entries (confirm)
  6974. /** --------------------------------------------*/
  6975. // Warning message if you try to delete an entry
  6976. //--------------------------------------------
  6977. function delete_entries_confirm()
  6978. {
  6979. global $IN, $DB, $DSP, $LANG;
  6980. if ( ! $DSP->allowed_group('can_delete_self_entries') AND
  6981. ! $DSP->allowed_group('can_delete_all_entries'))
  6982. {
  6983. return $DSP->no_access_message();
  6984. }
  6985. if ( ! $IN->GBL('toggle', 'POST'))
  6986. {
  6987. return $this->edit_entries();
  6988. }
  6989. $r = $DSP->form_open(array('action' => 'C=edit'.AMP.'M=delete_entries'));
  6990. $i = 0;
  6991. foreach ($_POST as $key => $val)
  6992. {
  6993. if (strstr($key, 'toggle') AND ! is_array($val))
  6994. {
  6995. if ($val != '')
  6996. {
  6997. $r .= $DSP->input_hidden('delete[]', $val);
  6998. $i++;
  6999. }
  7000. }
  7001. }
  7002. $r .= $DSP->qdiv('alertHeading', $LANG->line('delete_confirm'));
  7003. $r .= $DSP->div('box');
  7004. if ($i == 1)
  7005. $r .= $DSP->qdiv('defaultBold', $LANG->line('delete_entry_confirm'));
  7006. else
  7007. $r .= $DSP->qdiv('defaultBold', $LANG->line('delete_entries_confirm'));
  7008. // if it's just one entry, let's be kind and show a title
  7009. if (count($_POST['toggle']) == 1)
  7010. {
  7011. $query = $DB->query('SELECT title FROM exp_weblog_titles WHERE entry_id = "'.$DB->escape_str($_POST['toggle'][0]).'"');
  7012. if ($query->num_rows == 1)
  7013. {
  7014. $r .= $DSP->br(1).
  7015. $DSP->qdiv('defaultBold', str_replace('%title', $query->row['title'], $LANG->line('entry_title_with_title')));
  7016. }
  7017. }
  7018. $r .= $DSP->br(1).
  7019. $DSP->qdiv('alert', $LANG->line('action_can_not_be_undone')).
  7020. $DSP->br().
  7021. $DSP->input_submit($LANG->line('delete')).
  7022. $DSP->div_c().
  7023. $DSP->form_close();
  7024. $DSP->title = $LANG->line('delete_confirm');
  7025. $DSP->crumb = $LANG->line('delete_confirm');
  7026. $DSP->body = $r;
  7027. }
  7028. /* END */
  7029. /** --------------------------------------------
  7030. /** Delete Entries
  7031. /** --------------------------------------------*/
  7032. // Kill the specified entries
  7033. //--------------------------------------------
  7034. function delete_entries()
  7035. {
  7036. global $IN, $DSP, $LANG, $SESS, $DB, $FNS, $STAT, $EXT, $PREFS;
  7037. if ( ! $DSP->allowed_group('can_delete_self_entries') AND
  7038. ! $DSP->allowed_group('can_delete_all_entries'))
  7039. {
  7040. return $DSP->no_access_message();
  7041. }
  7042. if ( ! $IN->GBL('delete', 'POST'))
  7043. {
  7044. return $this->edit_entries();
  7045. }
  7046. // -------------------------------------------
  7047. // 'delete_entries_start' hook.
  7048. // - Take control of entry deletion script
  7049. //
  7050. $edata = $EXT->call_extension('delete_entries_start');
  7051. if ($EXT->end_script === TRUE) return;
  7052. //
  7053. // -------------------------------------------
  7054. $sql = 'SELECT weblog_id, author_id, entry_id FROM exp_weblog_titles WHERE (';
  7055. foreach ($_POST as $key => $val)
  7056. {
  7057. if (strstr($key, 'delete') AND ! is_array($val))
  7058. {
  7059. $sql .= " entry_id = '".$DB->escape_str($val)."' OR ";
  7060. }
  7061. }
  7062. $sql = substr($sql, 0, -3).')';
  7063. $query = $DB->query($sql);
  7064. $allowed_blogs = $FNS->fetch_assigned_weblogs();
  7065. $authors = array();
  7066. foreach ($query->result as $row)
  7067. {
  7068. if ($SESS->userdata['group_id'] != 1)
  7069. {
  7070. if ( ! in_array($row['weblog_id'], $allowed_blogs))
  7071. {
  7072. return $this->edit_entries();
  7073. }
  7074. }
  7075. if ($row['author_id'] == $SESS->userdata('member_id'))
  7076. {
  7077. if ( ! $DSP->allowed_group('can_delete_self_entries'))
  7078. {
  7079. return $DSP->no_access_message($LANG->line('unauthorized_to_delete_self'));
  7080. }
  7081. }
  7082. else
  7083. {
  7084. if ( ! $DSP->allowed_group('can_delete_all_entries'))
  7085. {
  7086. return $DSP->no_access_message($LANG->line('unauthorized_to_delete_others'));
  7087. }
  7088. }
  7089. $authors[$row['entry_id']] = $row['author_id'];
  7090. }
  7091. // gather related fields, we use this later if needed
  7092. $fquery = $DB->query("SELECT field_id FROM exp_weblog_fields WHERE field_type = 'rel'");
  7093. $entries = array();
  7094. foreach ($_POST as $key => $val)
  7095. {
  7096. if (strstr($key, 'delete') AND ! is_array($val))
  7097. {
  7098. if ( ! is_numeric($val))
  7099. continue;
  7100. $query = $DB->query("SELECT weblog_id FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($val)."'");
  7101. if ($query->num_rows == 0)
  7102. continue;
  7103. $entries[] = $val;
  7104. $weblog_id = $query->row['weblog_id'];
  7105. $DB->query("DELETE FROM exp_weblog_titles WHERE entry_id = '{$val}'");
  7106. $DB->query("DELETE FROM exp_weblog_data WHERE entry_id = '{$val}'");
  7107. $DB->query("DELETE FROM exp_category_posts WHERE entry_id = '{$val}'");
  7108. $DB->query("DELETE FROM exp_trackbacks WHERE entry_id = '{$val}'");
  7109. $DB->query("DELETE FROM exp_relationships WHERE rel_parent_id = '{$val}'");
  7110. /** -------------------------------------
  7111. /** Check for silly children
  7112. /** -------------------------------------*/
  7113. $child_results = $DB->query("SELECT rel_id FROM exp_relationships WHERE rel_child_id = '{$val}'");
  7114. if ($child_results->num_rows > 0)
  7115. {
  7116. // We have children, so we need to do a bit of housekeeping
  7117. // so parent entries don't continue to try to reference them
  7118. $cids = array();
  7119. foreach ($child_results->result as $row)
  7120. {
  7121. $cids[] = $row['rel_id'];
  7122. }
  7123. $CIDS = "'".implode("', '", $cids)."'";
  7124. foreach($fquery->result as $row)
  7125. {
  7126. $field = 'field_id_'.$row['field_id'];
  7127. $DB->query($DB->update_string('exp_weblog_data', array($field => '0'), "{$field} IN ({$CIDS})"));
  7128. }
  7129. $DB->query("DELETE FROM exp_relationships WHERE rel_child_id = '{$val}'");
  7130. }
  7131. $query = $DB->query("SELECT total_entries FROM exp_members WHERE member_id = '".$authors[$val]."'");
  7132. $tot = $query->row['total_entries'];
  7133. if ($tot > 0)
  7134. $tot -= 1;
  7135. $DB->query("UPDATE exp_members set total_entries = '".$tot."' WHERE member_id = '".$authors[$val]."'");
  7136. $query = $DB->query("SELECT count(*) AS count FROM exp_comments WHERE status = 'o' AND entry_id = '$val' AND author_id = '".$authors[$val]."'");
  7137. if ($query->row['count'] > 0)
  7138. {
  7139. $count = $query->row['count'];
  7140. $query = $DB->query("SELECT total_comments FROM exp_members WHERE member_id = '".$authors[$val]."'");
  7141. $DB->query("UPDATE exp_members set total_comments = '".($query->row['total_comments'] - $count)."' WHERE member_id = '".$authors[$val]."'");
  7142. }
  7143. $DB->query("DELETE FROM exp_comments WHERE entry_id = '$val'");
  7144. // -------------------------------------------
  7145. // 'delete_entries_loop' hook.
  7146. // - Add additional processing for entry deletion in loop
  7147. // - Added: 1.4.1
  7148. //
  7149. $edata = $EXT->call_extension('delete_entries_loop', $val, $weblog_id);
  7150. if ($EXT->end_script === TRUE) return;
  7151. //
  7152. // -------------------------------------------
  7153. // Update statistics
  7154. $STAT->update_weblog_stats($weblog_id);
  7155. $STAT->update_comment_stats($weblog_id);
  7156. $STAT->update_trackback_stats($weblog_id);
  7157. }
  7158. }
  7159. /** ----------------------------------------
  7160. /** Delete Pages Stored in Database For Entries
  7161. /** ----------------------------------------*/
  7162. if (sizeof($entries) > 0 && $PREFS->ini('site_pages') !== FALSE)
  7163. {
  7164. $pages = $PREFS->ini('site_pages');
  7165. if (sizeof($pages) > 0)
  7166. {
  7167. foreach($entries as $entry_id)
  7168. {
  7169. unset($pages['uris'][$entry_id]);
  7170. unset($pages['templates'][$entry_id]);
  7171. }
  7172. $PREFS->core_ini['site_pages'] = $pages;
  7173. $DB->query($DB->update_string('exp_sites',
  7174. array('site_pages' => addslashes(serialize($pages))),
  7175. "site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'"));
  7176. }
  7177. }
  7178. /** ---------------------------------
  7179. /** Clear caches
  7180. /** ---------------------------------*/
  7181. $FNS->clear_caching('all');
  7182. // -------------------------------------------
  7183. // 'delete_entries_end' hook.
  7184. // - Add additional processing for entry deletion
  7185. //
  7186. $edata = $EXT->call_extension('delete_entries_end');
  7187. if ($EXT->end_script === TRUE) return;
  7188. //
  7189. // -------------------------------------------
  7190. /** ----------------------------------------
  7191. /** Return success message
  7192. /** ----------------------------------------*/
  7193. $message = $DSP->div('success').$LANG->line('entries_deleted').$DSP->div_c();
  7194. return $this->edit_entries('', $message);
  7195. }
  7196. /* END */
  7197. /** --------------------------------------------
  7198. /** File upload form
  7199. /** --------------------------------------------*/
  7200. function file_upload_form()
  7201. {
  7202. global $IN, $DSP, $LANG, $SESS, $DB, $EXT, $PREFS;
  7203. // -------------------------------------------
  7204. // 'file_upload_form_start' hook.
  7205. // - Allows complete rewrite of File Upload Form page.
  7206. //
  7207. $edata = $EXT->call_extension('file_upload_form_start');
  7208. if ($EXT->end_script === TRUE) return;
  7209. //
  7210. // -------------------------------------------
  7211. $LANG->fetch_language_file('filebrowser');
  7212. $DSP->title = $LANG->line('file_upload');
  7213. $DSP->body = $DSP->qdiv('smallLinks', NBS);
  7214. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('file_upload'));
  7215. $DSP->body .= $DSP->div('box').BR;
  7216. if ($SESS->userdata['group_id'] == 1)
  7217. {
  7218. $query = $DB->query("SELECT id, name FROM exp_upload_prefs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n' ORDER BY name");
  7219. }
  7220. else
  7221. {
  7222. $sql = "SELECT id, name FROM exp_upload_prefs ";
  7223. if (USER_BLOG === FALSE)
  7224. {
  7225. $query = $DB->query("SELECT upload_id FROM exp_upload_no_access WHERE member_group = '".$SESS->userdata['group_id']."'");
  7226. $idx = array();
  7227. if ($query->num_rows > 0)
  7228. {
  7229. foreach ($query->result as $row)
  7230. {
  7231. $idx[] = $row['upload_id'];
  7232. }
  7233. }
  7234. $sql .= " WHERE is_user_blog = 'n' ";
  7235. if (count($idx) > 0)
  7236. {
  7237. foreach ($idx as $val)
  7238. {
  7239. $sql .= " AND id != '".$val."' ";
  7240. }
  7241. }
  7242. }
  7243. else
  7244. {
  7245. $sql .= " WHERE weblog_id = '".UB_BLOG_ID."' ORDER BY name";
  7246. }
  7247. $sql .= " AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  7248. $query = $DB->query($sql);
  7249. }
  7250. if ($query->num_rows == 0)
  7251. {
  7252. return $DSP->no_access_message();
  7253. }
  7254. $DSP->body .= "<form method=\"post\" action=\"".BASE.AMP.'C=publish'.AMP.'M=upload_file'.AMP.'Z=1'."\" enctype=\"multipart/form-data\">\n";
  7255. $DSP->body .= $DSP->input_hidden('field_group', $IN->GBL('field_group', 'GET'));
  7256. $DSP->body .= $DSP->qdiv('', "<input type=\"file\" name=\"userfile\" size=\"20\" />".BR.BR);
  7257. $DSP->body .= $DSP->qdiv('itemWrapper', $LANG->line('select_destination_dir'));
  7258. $DSP->body .= $DSP->input_select_header('destination');
  7259. foreach ($query->result as $row)
  7260. {
  7261. $DSP->body .= $DSP->input_select_option($row['id'], $row['name']);
  7262. }
  7263. $DSP->body .= $DSP->input_select_footer();
  7264. $DSP->body .= $DSP->qdiv('', BR.$DSP->input_submit($LANG->line('upload')).$DSP->br(2));
  7265. $DSP->body .= $DSP->form_close();
  7266. $DSP->body .= $DSP->div_c();
  7267. /** -------------------------------
  7268. /** File Browser
  7269. /** -------------------------------*/
  7270. $DSP->body .= $DSP->qdiv('', BR.BR);
  7271. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('file_browser'));
  7272. $DSP->body .= $DSP->div('box');
  7273. $DSP->body .= "<form method=\"post\" action=\"".BASE.AMP.'C=publish'.AMP.'M=file_browser'.AMP.'Z=1'."\" enctype=\"multipart/form-data\">\n";
  7274. $DSP->body .= $DSP->input_hidden('field_group', $IN->GBL('field_group', 'GET'));
  7275. $DSP->body .= $DSP->qdiv('itemWrapperTop', $LANG->line('select_destination_dir'));
  7276. $DSP->body .= $DSP->input_select_header('directory');
  7277. foreach ($query->result as $row)
  7278. {
  7279. $DSP->body .= $DSP->input_select_option($row['id'], $row['name']);
  7280. }
  7281. $DSP->body .= $DSP->input_select_footer();
  7282. $DSP->body .= $DSP->qdiv('', BR.$DSP->input_submit($LANG->line('view')));
  7283. $DSP->body .= $DSP->form_close();
  7284. $DSP->body .= BR.BR.$DSP->div_c();
  7285. $DSP->body .= $DSP->qdiv('itemWrapper', BR.'<div align="center"><a href="JavaScript:window.close();">'.$LANG->line('close_window').'</a></div>');
  7286. /** ---------------------------
  7287. /** End File Browser
  7288. /** ---------------------------*/
  7289. }
  7290. /* END */
  7291. /** ----------------------------------
  7292. /** Upload File
  7293. /** ----------------------------------*/
  7294. function upload_file()
  7295. {
  7296. global $IN, $DSP, $DB, $LANG, $SESS;
  7297. $id = $IN->GBL('destination');
  7298. $field_group = $IN->GBL('field_group');
  7299. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($id)."'");
  7300. if ($query->num_rows == 0)
  7301. {
  7302. return;
  7303. }
  7304. if ($SESS->userdata['group_id'] != 1)
  7305. {
  7306. $safety = $DB->query("SELECT count(*) AS count FROM exp_upload_no_access WHERE upload_id = '".$query->row['id']."' AND upload_loc = 'cp' AND member_group = '".$SESS->userdata['group_id']."'");
  7307. if ($safety->row['count'] != 0)
  7308. {
  7309. exit('no access');
  7310. return $DSP->no_access_message();
  7311. }
  7312. }
  7313. require PATH_CORE.'core.upload'.EXT;
  7314. $UP = new Upload();
  7315. if ($UP->set_upload_path($query->row['server_path']) !== TRUE)
  7316. {
  7317. return $UP->show_error();
  7318. }
  7319. $UP->set_max_width($query->row['max_width']);
  7320. $UP->set_max_height($query->row['max_height']);
  7321. $UP->set_max_filesize($query->row['max_size']);
  7322. $UP->set_allowed_types(($SESS->userdata['group_id'] == 1) ? 'all' : $query->row['allowed_types']);
  7323. if ( ! $UP->upload_file())
  7324. {
  7325. return $UP->show_error();
  7326. }
  7327. global $UL; $UL = $UP;
  7328. if ($UL->file_exists == TRUE)
  7329. {
  7330. return $this->file_exists_warning();
  7331. }
  7332. $this->finalize_uploaded_file(
  7333. array(
  7334. 'id' => $id,
  7335. 'field_group' => $field_group,
  7336. 'file_name' => $UP->file_name,
  7337. 'is_image' => $UP->is_image,
  7338. 'step' => 1
  7339. )
  7340. );
  7341. }
  7342. /* END */
  7343. /** ----------------------------------
  7344. /** File Browser
  7345. /** ----------------------------------*/
  7346. function file_browser()
  7347. {
  7348. global $IN, $DSP, $DB, $LANG, $SESS, $EXT;
  7349. // -------------------------------------------
  7350. // 'file_browser_start' hook.
  7351. // - Allows complete rewrite of File Browser page.
  7352. //
  7353. $edata = $EXT->call_extension('file_browser_start');
  7354. if ($EXT->end_script === TRUE) return;
  7355. //
  7356. // -------------------------------------------
  7357. $LANG->fetch_language_file('filebrowser');
  7358. $id = $IN->GBL('directory');
  7359. $field_group = $IN->GBL('field_group');
  7360. $DSP->title = $LANG->line('file_browser');
  7361. $r = $DSP->qdiv('tableHeading', $LANG->line('file_browser'));
  7362. $r .= $DSP->div('box');
  7363. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($id)."'");
  7364. if ($query->num_rows == 0)
  7365. {
  7366. return;
  7367. }
  7368. if ($SESS->userdata['group_id'] != 1)
  7369. {
  7370. $safety = $DB->query("SELECT count(*) AS count FROM exp_upload_no_access WHERE upload_id = '".$query->row['id']."' AND upload_loc = 'cp' AND member_group = '".$SESS->userdata['group_id']."'");
  7371. if ($safety->row['count'] != 0)
  7372. {
  7373. exit('no access');
  7374. return $DSP->no_access_message();
  7375. }
  7376. }
  7377. if (! class_exists('File_Browser'))
  7378. {
  7379. require PATH_CP.'cp.filebrowser'.EXT;
  7380. }
  7381. $FP = new File_Browser();
  7382. $FP->set_upload_path($query->row['server_path']);
  7383. $directory_url = $query->row['url'];
  7384. $pre_format = addslashes($query->row['pre_format']);
  7385. $post_format = addslashes($query->row['post_format']);
  7386. $properties = ($query->row['properties'] != '') ? " ".addslashes($query->row['properties']) : "";
  7387. $file_pre_format = addslashes($query->row['file_pre_format']);
  7388. $file_post_format = addslashes($query->row['file_post_format']);
  7389. $file_properties = ($query->row['file_properties'] != '') ? " ".addslashes($query->row['file_properties']) : "";
  7390. $FP->create_filelist();
  7391. if (sizeof($FP->filelist) == 0)
  7392. {
  7393. return $DSP->error_message($LANG->line('fp_no_files'));
  7394. }
  7395. $r .= <<<EOT
  7396. <script type="text/javascript">
  7397. <!--
  7398. var item=new Array();
  7399. var width=new Array();
  7400. var height=new Array();
  7401. EOT;
  7402. foreach ($FP->filelist as $key => $file_info)
  7403. {
  7404. $r .= "item[$key] = '".addslashes($file_info['name'])."';\n";
  7405. if ($file_info['type'] == 'image')
  7406. {
  7407. $r .= "width[$key] = ".$file_info['width'].";\n";
  7408. $r .= "height[$key] = ".$file_info['height'].";\n";
  7409. }
  7410. }
  7411. $r .= <<<EOT
  7412. function showimage()
  7413. {
  7414. var loc_w = 350;
  7415. var loc_h = 0;
  7416. for (var i=0; i < document.browser.elements['file[]'].length; i++)
  7417. {
  7418. if (document.browser.elements['file[]'].options[i].selected == true)
  7419. {
  7420. var t = document.browser.elements['file[]'].options[i].value;
  7421. if (width[t])
  7422. {
  7423. var loc = '{$directory_url}'+item[t];
  7424. window.open(loc,'Image'+t,'width='+width[t]+',height='+height[t]+',screenX='+loc_w+',screenY='+loc_h+',top='+loc_h+',left='+loc_w+',toolbar=0,status=0,scrollbars=0,location=0,menubar=1,resizable=1');
  7425. loc_w = loc_w + width[t];
  7426. loc_h = loc_h + 100;
  7427. }
  7428. }
  7429. }
  7430. return false;
  7431. }
  7432. function fileplacer()
  7433. {
  7434. var done = 'n';
  7435. var file = '';
  7436. var insert = '';
  7437. var field_value = 'field_id_1';
  7438. var pre_format = '{$pre_format}';
  7439. var post_format = '{$post_format}';
  7440. var properties = '{$properties}';
  7441. var file_pre_format = '{$file_pre_format}';
  7442. var file_post_format = '{$file_post_format}';
  7443. var file_properties = '{$file_properties}';
  7444. for (var i=0; i < document.browser.field.length; i++)
  7445. {
  7446. if (document.browser.field.options[i].selected == true)
  7447. {
  7448. field_value = document.browser.field.options[i].value;
  7449. }
  7450. }
  7451. for (var i=0; i < document.browser.elements['file[]'].length; i++)
  7452. {
  7453. if (document.browser.elements['file[]'].options[i].selected == true)
  7454. {
  7455. done = 'n';
  7456. var t = document.browser.elements['file[]'].options[i].value;
  7457. if (width[t])
  7458. {
  7459. var file = item[t];
  7460. file = '<img src="{filedir_{$id}}' + file + '"'+ properties + ' width="'+width[t]+'" height="'+height[t]+'" />';
  7461. var input = pre_format + file + post_format
  7462. opener.document.getElementById('entryform').elements[field_value].value += input+' ';
  7463. done = 'y';
  7464. }
  7465. if (done == 'n')
  7466. {
  7467. var file = item[t];
  7468. file = '<a href="{filedir_{$id}}' + file + '"'+ file_properties + '>'+file+'</a>';
  7469. var input = file_pre_format + file + file_post_format
  7470. opener.document.getElementById('entryform').elements[field_value].value += input;
  7471. }
  7472. }
  7473. }
  7474. return false;
  7475. }
  7476. function urlplacer()
  7477. {
  7478. var field_value = 'field_id_1';
  7479. var insert_value = '';
  7480. for (var i=0; i < document.browser.field.length; i++)
  7481. {
  7482. if (document.browser.field.options[i].selected == true)
  7483. {
  7484. field_value = document.browser.field.options[i].value;
  7485. }
  7486. }
  7487. for (var i=0; i < document.browser.elements['file[]'].length; i++)
  7488. {
  7489. if (document.browser.elements['file[]'].options[i].selected == true)
  7490. {
  7491. var t = document.browser.elements['file[]'].options[i].value;
  7492. insert_value += '{filedir_{$id}}' + item[t] + ' ';
  7493. }
  7494. }
  7495. if (insert_value.length > 0)
  7496. {
  7497. opener.document.getElementById('entryform').elements[field_value].value += insert_value.slice(0, insert_value.length - 1);
  7498. }
  7499. return false;
  7500. }
  7501. //-->
  7502. </script>
  7503. EOT;
  7504. $r .= "<form method=\"post\" name='browser' action=\"".BASE.AMP.'C=publish'.AMP.'M=file_browser'."\" enctype=\"multipart/form-data\">\n";
  7505. $r .= $DSP->input_hidden('directory', $id);
  7506. $r .= $DSP->qdiv('itemTitle', $LANG->line('fb_select_files'));
  7507. $r .= $DSP->div('itemWrapper').$DSP->input_select_header('file[]','y',10);
  7508. foreach ($FP->filelist as $key => $file_info)
  7509. {
  7510. $display_name = (isset($file_info['type']) && $file_info['type'] == 'image') ? $file_info['name'].NBS.NBS.NBS : $file_info['name'].'*'.NBS.NBS.NBS;
  7511. $r .= $DSP->input_select_option($key, $display_name);
  7512. }
  7513. $r .= $DSP->input_select_footer().$DSP->div_c();
  7514. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE group_id = '".$field_group."' AND field_type NOT IN ('date', 'rel', 'select') ORDER BY field_order");
  7515. $r .= $DSP->div('itemWrapper').$DSP->qdiv('itemTitle', $LANG->line('fb_select_field'));
  7516. $r .= $DSP->input_select_header('field');
  7517. foreach ($query->result as $row)
  7518. {
  7519. $r .= $DSP->qdiv('', $DSP->input_select_option('field_id_'.$row['field_id'], $row['field_label']));
  7520. }
  7521. $r .= $DSP->input_select_footer().$DSP->div_c();
  7522. $view_text = (sizeof($FP->filelist) > 1) ? $LANG->line('fb_view_images') : $LANG->line('fb_view_image');
  7523. $insert_text = (sizeof($FP->filelist) > 1) ? $LANG->line('fb_insert_links') : $LANG->line('fb_insert_link');
  7524. $url_text = (sizeof($FP->filelist) > 1) ? $LANG->line('fb_insert_urls') : $LANG->line('fb_insert_url');
  7525. $r .= $DSP->qdiv('', BR.$DSP->input_submit($view_text,'submit',' onclick="return showimage(); return false;"')
  7526. .NBS.NBS
  7527. .$DSP->input_submit($insert_text, 'submit',' onclick="return fileplacer(); return false;"')
  7528. .NBS.NBS
  7529. .$DSP->input_submit($url_text, 'submit',' onclick="return urlplacer(); return false;"'));
  7530. $r .= $DSP->form_close();
  7531. $r .= BR.BR.$DSP->div_c();
  7532. $r .= $DSP->qdiv('defaultCenter',BR.$LANG->line('fb_non_images'));
  7533. $r .= $DSP->qdiv('defaultCenter', BR.'<a href="JavaScript:window.close();">'.$LANG->line('close_window').'</a>');
  7534. $DSP->body = $r;
  7535. }
  7536. /* END */
  7537. /** --------------------------------------------
  7538. /** File Exists Warning message
  7539. /** --------------------------------------------*/
  7540. function file_exists_warning()
  7541. {
  7542. global $IN, $DSP, $LANG, $UL;
  7543. $field_group = $IN->GBL('field_group');
  7544. $original_file = (isset($_FILES['userfile']['name'])) ? $_FILES['userfile']['name'] : $_POST['original_file'];
  7545. $file_name = (isset($_POST['file_name'])) ? $_POST['file_name'] : $_FILES['userfile']['name'];
  7546. $destination = (isset($_POST['id'])) ? $_POST['id'] : $_POST['destination'];
  7547. $is_image = (isset($_POST['is_image'])) ? $_POST['is_image'] : $UL->is_image;
  7548. $width = (isset($_POST['width'])) ? $_POST['width'] : $UL->width;
  7549. $height = (isset($_POST['height'])) ? $_POST['height'] : $UL->height;
  7550. $imgtype = (isset($_POST['imgtype'])) ? $_POST['imgtype'] : $UL->imgtype;
  7551. $DSP->title = $LANG->line('file_upload');
  7552. $DSP->body .= $DSP->qdiv('smallLinks', NBS);
  7553. $DSP->body .= $DSP->qdiv('alertHeading', $LANG->line('warning'));
  7554. $DSP->body .= $DSP->div('box');
  7555. $DSP->body .= $DSP->qdiv('highlight', $LANG->line('file_exists'));
  7556. $DSP->body .= $DSP->qdiv('itemWrapperTop', $LANG->line('overwrite_instructions'));
  7557. $DSP->body .= $DSP->form_open(array('action' => 'C=publish'.AMP.'M=replace_file'.AMP.'Z=1'));
  7558. $DSP->body .= $DSP->input_text('file_name', $file_name, '40', '100', 'input', '200px');
  7559. $DSP->body .= $DSP->input_hidden('original_file', $original_file);
  7560. $DSP->body .= $DSP->input_hidden('temp_file_name', $file_name);
  7561. $DSP->body .= $DSP->input_hidden('field_group', $field_group);
  7562. $DSP->body .= $DSP->input_hidden('is_image', $is_image);
  7563. $DSP->body .= $DSP->input_hidden('width', $width);
  7564. $DSP->body .= $DSP->input_hidden('height', $height);
  7565. $DSP->body .= $DSP->input_hidden('imgtype', $imgtype);
  7566. $DSP->body .= $DSP->input_hidden('id', $destination);
  7567. $DSP->body .= $DSP->qdiv('', BR.$DSP->input_submit($LANG->line('submit')));
  7568. $DSP->body .= $DSP->form_close();
  7569. $DSP->body .= BR.$DSP->div_c();
  7570. $DSP->body .= $DSP->qdiv('itemWrapper', BR.'<div align="center"><a href="JavaScript:window.close();">'.$LANG->line('close_window').'</a></div>');
  7571. }
  7572. /* END */
  7573. /** -----------------------------------
  7574. /** Overwrite file
  7575. /** -----------------------------------*/
  7576. function replace_file()
  7577. {
  7578. global $IN, $DSP, $LANG, $DB, $SESS;
  7579. $id = $IN->GBL('id');
  7580. $file_name = $IN->GBL('file_name');
  7581. $temp_file_name = $IN->GBL('temp_file_name');
  7582. $is_image = $IN->GBL('is_image');
  7583. $field_group = $IN->GBL('field_group');
  7584. require PATH_CORE.'core.upload'.EXT;
  7585. $UP = new Upload();
  7586. if ($UP->remove_spaces == 1)
  7587. {
  7588. $file_name = preg_replace("/\s+/", "_", $file_name);
  7589. $temp_file_name = preg_replace("/\s+/", "_", $temp_file_name);
  7590. }
  7591. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($id)."'");
  7592. if ($SESS->userdata['group_id'] != 1)
  7593. {
  7594. $safety = $DB->query("SELECT count(*) AS count FROM exp_upload_no_access
  7595. WHERE upload_id = '".$DB->escape_str($query->row['id'])."'
  7596. AND upload_loc = 'cp'
  7597. AND member_group = '".$DB->escape_str($SESS->userdata['group_id'])."'");
  7598. if ($safety->row['count'] != 0)
  7599. {
  7600. return $DSP->no_access_message();
  7601. }
  7602. }
  7603. if ($UP->set_upload_path($query->row['server_path']) !== TRUE)
  7604. {
  7605. return $UP->show_error();
  7606. }
  7607. $UP->set_max_width($query->row['max_width']);
  7608. $UP->set_max_height($query->row['max_height']);
  7609. $UP->set_max_filesize($query->row['max_size']);
  7610. $UP->set_allowed_types(($SESS->userdata['group_id'] == 1) ? 'all' : $query->row['allowed_types']);
  7611. $UP->set_upload_path($query->row['server_path']);
  7612. if ($temp_file_name != $file_name)
  7613. {
  7614. if (file_exists($query->row['server_path'].$file_name))
  7615. {
  7616. return $this->file_exists_warning();
  7617. }
  7618. }
  7619. if ( ! $UP->file_overwrite() === TRUE)
  7620. {
  7621. return $UP->show_error();
  7622. }
  7623. $this->finalize_uploaded_file(
  7624. array(
  7625. 'id' => $id,
  7626. 'field_group' => $field_group,
  7627. 'file_name' => $file_name,
  7628. 'is_image' => $is_image,
  7629. 'step' => 1
  7630. )
  7631. );
  7632. }
  7633. /* END */
  7634. /** --------------------------------------------
  7635. /** Image options form
  7636. /** --------------------------------------------*/
  7637. function image_options_form()
  7638. {
  7639. global $IN, $DSP, $LANG, $DB, $UL;
  7640. $id = (isset($_POST['id'])) ? $_POST['id'] : $_POST['destination'];
  7641. $file_name = (isset($_POST['file_name'])) ? $_POST['file_name'] : $_FILES['userfile']['name'];
  7642. $is_image = (isset($_POST['is_image'])) ? $_POST['is_image'] : $UL->is_image;
  7643. $width = (isset($_POST['width'])) ? $_POST['width'] : $UL->width;
  7644. $height = (isset($_POST['height'])) ? $_POST['height'] : $UL->height;
  7645. $imgtype = (isset($_POST['imgtype'])) ? $_POST['imgtype'] : $UL->imgtype; // 2 = jpg 3 = png
  7646. $field_group = $IN->GBL('field_group');
  7647. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($id)."'");
  7648. $max_w = ($query->row['max_width'] == '') ? '1000' : $query->row['max_width'];
  7649. $max_h = ($query->row['max_height'] == '') ? '1000' : $query->row['max_height'];
  7650. $max_w = str_replace(array(',', '.'), array('', ''), $max_w);
  7651. $max_h = str_replace(array(',', '.'), array('', ''), $max_h);
  7652. $DSP->title = $LANG->line('file_upload');
  7653. ob_start();
  7654. ?>
  7655. <script type="text/javascript">
  7656. function changeDimUnits(f, side)
  7657. {
  7658. var unit = (side == "w")? f.width_unit : f.height_unit;
  7659. var orig = (side == "w")? f.width_orig : f.height_orig;
  7660. var curr = (side == "w")? f.width : f.height;
  7661. curr.value = (unit.options[unit.selectedIndex].value == "pixels") ? Math.round(orig.value * curr.value / 100.0) : Math.round((curr.value / orig.value) * 100.0);
  7662. return;
  7663. }
  7664. function changeDimValue(f, side)
  7665. {
  7666. var max = (side == "h") ? <?php echo $max_w; ?> : <?php echo $max_h; ?>;
  7667. var max_alt = (side == "h") ? <?php echo $max_h; ?> : <?php echo $max_w; ?>;
  7668. var unit = (side == "w") ? f.width_unit : f.height_unit;
  7669. var orig = (side == "w") ? f.width_orig : f.height_orig;
  7670. var curr = (side == "w") ? f.width : f.height;
  7671. var t_unit = (side == "h") ? f.width_unit : f.height_unit;
  7672. var t_orig = (side == "h") ? f.width_orig : f.height_orig;
  7673. var t_curr = (side == "h") ? f.width : f.height;
  7674. var ratio = (unit.options[unit.selectedIndex].value == "pixels") ? curr.value/orig.value : curr.value/100;
  7675. var res = (t_unit.value == "pixels") ? Math.floor(ratio * t_orig.value) : Math.round(ratio * 100);
  7676. var res_alt = (unit.value == "pixels") ? Math.floor(ratio * orig.value) : Math.round(ratio * 100);
  7677. if (res > max || res_alt > max_alt)
  7678. {
  7679. if (f.constrain.checked)
  7680. t_curr.value = t_orig.value;
  7681. if (f.constrain.checked || res_alt > max_alt)
  7682. curr.value = (unit.options[unit.selectedIndex].value == "pixels") ?
  7683. Math.min(curr.value, orig.value) : curr.value = Math.min(curr.value, 100);
  7684. }
  7685. else
  7686. {
  7687. if (f.constrain.checked)
  7688. t_curr.value = res;
  7689. }
  7690. return;
  7691. }
  7692. </script>
  7693. <?php
  7694. $DSP->body .= ob_get_contents();
  7695. ob_end_clean();
  7696. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('resize_image'));
  7697. $DSP->body .= $DSP->div('box');
  7698. $DSP->body .= $DSP->qdiv('', $LANG->line('thumb_instructions').NBS.NBS.$LANG->line('close_for_no_change'));
  7699. $DSP->body .= $DSP->form_open(
  7700. array(
  7701. 'action' => 'C=publish'.AMP.'M=create_thumb'.AMP.'Z=1',
  7702. 'name' => 'fileOptions',
  7703. 'id' => 'fileOptions',
  7704. ),
  7705. array(
  7706. 'field_group' => $field_group,
  7707. 'is_image' => $is_image,
  7708. 'imgtype' => $imgtype,
  7709. 'file_name' => $file_name,
  7710. 'id' => $id,
  7711. 'width_orig' => $width,
  7712. 'height_orig' => $height
  7713. )
  7714. );
  7715. $DSP->body .= BR."<fieldset class='thumb' name=\"thumb_settings\" id=\"thumb_settings\" >";
  7716. $DSP->body .= "<legend>".$LANG->line('thumb_settings')."</legend>";
  7717. $DSP->body .= $DSP->div('thumbPad');
  7718. $DSP->body .= $DSP->table('', '6', '0', '');
  7719. $DSP->body .= $DSP->table_qrow( 'none',
  7720. array(
  7721. NBS.$LANG->line('width'),
  7722. $DSP->input_text('width', $width, '4', '4', 'input', '40px', " onchange=\"changeDimValue(this.form, 'w');\" "),
  7723. "<select name='width_unit' class='select' onchange=\"changeDimUnits(this.form, 'w')\" >".
  7724. $DSP->input_select_option('pixels', $LANG->line('pixels'), 1).
  7725. $DSP->input_select_option('percent',$LANG->line('percent')).
  7726. $DSP->input_select_footer()
  7727. )
  7728. );
  7729. $DSP->body .= $DSP->table_qrow( 'none',
  7730. array(
  7731. $LANG->line('height'),
  7732. $DSP->input_text('height', $height, '4', '4', 'input', '40px', " onchange=\"changeDimValue(this.form, 'h');\" "),
  7733. "<select name='height_unit' class='select' onchange=\"changeDimUnits(this.form, 'h')\" >".
  7734. $DSP->input_select_option('pixels', $LANG->line('pixels'), 1).
  7735. $DSP->input_select_option('percent', $LANG->line('percent')).
  7736. $DSP->input_select_footer()
  7737. )
  7738. );
  7739. $DSP->body .= $DSP->tr();
  7740. $DSP->body .= $DSP->td('none', '', '3');
  7741. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('constrain', '1', 1).NBS.$LANG->line('constrain_proportions'));
  7742. $DSP->body .= $DSP->qdiv('', BR.$DSP->input_radio('source', 'copy', 1).NBS.$LANG->line('create_thumb_copy'));
  7743. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('source', 'orig').NBS.$LANG->line('resize_original'));
  7744. $DSP->body .= $DSP->td_c();
  7745. $DSP->body .= $DSP->tr_c();
  7746. $DSP->body .= $DSP->table_c();
  7747. $DSP->body .= $DSP->div_c();
  7748. $DSP->body .= "</fieldset>";
  7749. $DSP->body .= $DSP->qdiv('itemWrapper', BR.$DSP->input_submit($LANG->line('resize_image')));
  7750. $DSP->body .= BR.$DSP->div_c();
  7751. $DSP->body .= $DSP->qdiv('itemWrapper', BR.'<div align="center"><a href="JavaScript:window.close();">'.$LANG->line('close_window').'</a></div>');
  7752. $DSP->body .= $DSP->form_close();
  7753. }
  7754. /* END */
  7755. /** -----------------------------------
  7756. /** Create image thumbnail
  7757. /** -----------------------------------*/
  7758. function create_thumb()
  7759. {
  7760. global $IN, $DSP, $LANG, $PREFS, $LANG, $DB;
  7761. if ($_POST['width_unit'] == 'percent')
  7762. {
  7763. $_POST['width'] = ceil($_POST['width']/100 * $_POST['width_orig']);
  7764. }
  7765. if ($_POST['height_unit'] == 'percent')
  7766. {
  7767. $_POST['height'] = ceil($_POST['height']/100 * $_POST['height_orig']);
  7768. }
  7769. foreach ($_POST as $key => $val)
  7770. {
  7771. $$key = $val;
  7772. }
  7773. //print_r($_POST); exit;
  7774. if ($width == $width_orig AND $height == $height_orig)
  7775. {
  7776. return $DSP->error_message($LANG->line('image_size_not_different'));
  7777. }
  7778. if ($width != $width_orig OR $height_orig != $height)
  7779. {
  7780. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($id)."'");
  7781. $thumb_prefix = ($PREFS->ini('thumbnail_prefix') == '') ? 'thumb' : $PREFS->ini('thumbnail_prefix');
  7782. /** --------------------------------
  7783. /** Invoke the Image Lib Class
  7784. /** --------------------------------*/
  7785. require PATH_CORE.'core.image_lib'.EXT;
  7786. $IM = new Image_lib();
  7787. /** --------------------------------
  7788. /** Resize the image
  7789. /** --------------------------------*/
  7790. $res = $IM->set_properties(
  7791. array(
  7792. 'resize_protocol' => $PREFS->ini('image_resize_protocol'),
  7793. 'libpath' => $PREFS->ini('image_library_path'),
  7794. 'thumb_prefix' => ($source == 'orig') ? '' : $thumb_prefix,
  7795. 'file_path' => $query->row['server_path'],
  7796. 'file_name' => $file_name,
  7797. 'dst_width' => $width,
  7798. 'dst_height' => $height,
  7799. 'maintain_ratio' => FALSE
  7800. )
  7801. );
  7802. if ($res === FALSE OR ! $IM->image_resize())
  7803. {
  7804. return $IM->show_error();
  7805. }
  7806. }
  7807. $this->finalize_uploaded_file(
  7808. array(
  7809. 'id' => $id,
  7810. 'field_group' => $field_group,
  7811. 'orig_name' => $file_name,
  7812. 'file_name' => $IM->thumb_name,
  7813. 'is_image' => 1,
  7814. 'step' => 2,
  7815. 'source' => $source
  7816. )
  7817. );
  7818. }
  7819. /* END */
  7820. /** ---------------------------------------
  7821. /** Finalize Uploaded File
  7822. /** ---------------------------------------*/
  7823. function finalize_uploaded_file($data)
  7824. {
  7825. global $IN, $DSP, $LANG, $PREFS, $DB;
  7826. // Fetch upload preferences
  7827. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '".$DB->escape_str($data['id'])."'");
  7828. if ($data['is_image'] == 1)
  7829. {
  7830. $properties = ($query->row['properties'] != '') ? " ".addslashes($query->row['properties']) : "";
  7831. }
  7832. else
  7833. {
  7834. $properties = ($query->row['file_properties'] != '') ? " ".addslashes($query->row['file_properties']) : "";
  7835. }
  7836. $popup_link = '';
  7837. $popup_thumb = '';
  7838. $pre_format = addslashes($query->row['pre_format']);
  7839. $post_format = addslashes($query->row['post_format']);
  7840. $file_pre_format = addslashes($query->row['file_pre_format']);
  7841. $file_post_format = addslashes($query->row['file_post_format']);
  7842. $file_url = '{filedir_'.$data['id'].'}'.$data['file_name'];
  7843. $props = ($data['is_image'] == 1) ? $pre_format : $file_pre_format;
  7844. if ($data['is_image'] == 1)
  7845. {
  7846. $imgsrc = '<img src="'.$file_url.'"'.$properties;
  7847. $wh = '';
  7848. if (function_exists('getimagesize'))
  7849. {
  7850. $imgdim = @getimagesize($query->row['server_path'].$data['file_name']);
  7851. if (is_array($imgdim))
  7852. {
  7853. $imgsrc .= " width=\"".$imgdim['0']."\" height=\"".$imgdim['1']."\"";
  7854. $wh = "width=".($imgdim['0']+15).",height=".($imgdim['1']+15).",";
  7855. }
  7856. if (isset($data['orig_name']) AND $data['orig_name'] != '')
  7857. {
  7858. $imgdim = @getimagesize($query->row['server_path'].$data['orig_name']);
  7859. if (is_array($imgdim))
  7860. {
  7861. $wh = "width=".($imgdim['0']+15).",height=".($imgdim['1']+15).",";
  7862. }
  7863. }
  7864. }
  7865. $imgsrc .= " />";
  7866. $filename = (isset($data['orig_name']) AND $data['orig_name'] != '') ? $data['orig_name'] : $data['file_name'];
  7867. $eh = "onclick=\"window.open(\'{filedir_".$data['id']."}".$filename."\',\'popup\',\'".$wh."scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false\"";
  7868. $popup_link = $props."<a href=\"{filedir_".$data['id']."}".$filename."\" $eh>".$filename."</a>".$post_format;
  7869. $popup_thumb = $props."<a href=\"{filedir_".$data['id']."}".$filename."\" $eh>".$imgsrc."</a>".$post_format;
  7870. $props .= $imgsrc;
  7871. }
  7872. else
  7873. {
  7874. $props .= '<a href="'.$file_url.'"'.$properties.'>'.$data['file_name'].'</a>';
  7875. }
  7876. $props .= ($data['is_image'] == 1) ? $post_format : $file_post_format;
  7877. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE group_id = '".$data['field_group']."' AND field_type NOT IN ('date', 'rel', 'select') ORDER BY field_order");
  7878. if ($query->num_rows == 0)
  7879. {
  7880. return $DSP->error_message($LANG->line('no_entry_fields'));
  7881. }
  7882. ob_start();
  7883. ?>
  7884. <script type="text/javascript">
  7885. <!--
  7886. function fileplacer()
  7887. {
  7888. if (document.upload.style[1].checked)
  7889. {
  7890. var file = '<?php echo $file_url; ?>';
  7891. }
  7892. else if (document.upload.nonimage.value == 'yes')
  7893. {
  7894. var file = '<?php echo $props; ?>';
  7895. }
  7896. else
  7897. {
  7898. if (document.upload.style[0].checked)
  7899. {
  7900. var file = '<?php echo $props; ?>';
  7901. }
  7902. else if (document.upload.style[2].checked)
  7903. {
  7904. var file = '<?php echo $popup_link; ?>';
  7905. }
  7906. else
  7907. {
  7908. var file = '<?php echo $popup_thumb; ?>';
  7909. }
  7910. }
  7911. <?php
  7912. $n = 0;
  7913. foreach ($query->result as $row)
  7914. {
  7915. ?>
  7916. if (document.upload.which[<?php echo $n; ?>].selected)
  7917. {
  7918. opener.document.getElementById('entryform').field_id_<?php echo $row['field_id']; ?>.value += file;
  7919. }
  7920. <?php
  7921. $n++;
  7922. }
  7923. ?>
  7924. return false;
  7925. }
  7926. //-->
  7927. </script>
  7928. <?php
  7929. $javascript = ob_get_contents();
  7930. ob_end_clean();
  7931. $DSP->title = $LANG->line('file_upload');
  7932. $DSP->body = $javascript;
  7933. $DSP->body .= $DSP->div('box');
  7934. if ($data['step'] == 1)
  7935. {
  7936. $DSP->body .= $DSP->div('itemWrapper');
  7937. $DSP->body .= $DSP->qspan('success', $LANG->line('file_uploaded').NBS);
  7938. $DSP->body .= $DSP->qspan('defaultBold', $data['file_name']);
  7939. $DSP->body .= $DSP->div_c();
  7940. }
  7941. else
  7942. {
  7943. if (isset($data['source']) AND $data['source'] == 'copy')
  7944. $DSP->body .= $DSP->qdiv('success', $LANG->line('thumbnail_created'));
  7945. else
  7946. $DSP->body .= $DSP->qdiv('success', $LANG->line('image_resized'));
  7947. }
  7948. $DSP->body .= $DSP->div_c();
  7949. if ($data['step'] == 1 AND $data['is_image'] == 1 AND $PREFS->ini('enable_image_resizing') == 'y')
  7950. {
  7951. $DSP->body .= "<form name='upload' method='post' action='".BASE.AMP.'C=publish'.AMP.'M=image_options'.AMP.'Z=1'."' >";
  7952. global $UL;
  7953. $width = (isset($_POST['width'])) ? $_POST['width'] : $UL->width;
  7954. $height = (isset($_POST['height'])) ? $_POST['height'] : $UL->height;
  7955. $imgtype = (isset($_POST['imgtype'])) ? $_POST['imgtype'] : $UL->imgtype; // 2 = jpg 3 = png
  7956. $DSP->body .= $DSP->input_hidden('id', $data['id']);
  7957. $DSP->body .= $DSP->input_hidden('field_group', $data['field_group']);
  7958. $DSP->body .= $DSP->input_hidden('is_image', $data['is_image']);
  7959. $DSP->body .= $DSP->input_hidden('file_name', $data['file_name']);
  7960. $DSP->body .= $DSP->input_hidden('width', $width);
  7961. $DSP->body .= $DSP->input_hidden('height', $height);
  7962. $DSP->body .= $DSP->input_hidden('imgtype', $imgtype);
  7963. $DSP->body .= $DSP->qdiv('smallLinks', NBS);
  7964. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('resize_image'));
  7965. $DSP->body .= $DSP->div('box');
  7966. $DSP->body .= $DSP->qdiv('itemWrapper', $LANG->line('thumb_instructions'));
  7967. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('thumb_info')));
  7968. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('resize_image')));
  7969. $DSP->body .= $DSP->qdiv('smallLinks', '');
  7970. $DSP->body .= $DSP->div_c();
  7971. }
  7972. else
  7973. {
  7974. $DSP->body .= "<form name='upload' method='post' action='JavaScript:window.close()' >";
  7975. }
  7976. $DSP->body .= $DSP->qdiv('smallLinks', NBS);
  7977. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('select_action'));
  7978. $DSP->body .= $DSP->div('box');
  7979. if ($data['is_image'] == 1)
  7980. {
  7981. $DSP->body .= $DSP->input_hidden('nonimage', 'no');
  7982. $DSP->body .= "<fieldset class='thumb' name=\"thumb_settings\" id=\"thumb_settings\" >";
  7983. $DSP->body .= "<legend>&nbsp;<b>".$LANG->line('file_type')."</b>&nbsp;</legend>";
  7984. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'embed', 1).NBS.$LANG->line('embedded'));
  7985. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'url', '').NBS.$LANG->line('url_only'));
  7986. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'popuplink', '').NBS.$LANG->line('popup_link'));
  7987. if (isset($_POST['source']) AND $_POST['source'] == 'copy')
  7988. {
  7989. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'popupthumb', '').NBS.$LANG->line('popup_thumb'));
  7990. }
  7991. $DSP->body .= "</fieldset>";
  7992. }
  7993. else
  7994. {
  7995. $DSP->body .= $DSP->input_hidden('nonimage', 'yes');
  7996. $DSP->body .= "<fieldset class='thumb' name=\"thumb_settings\" id=\"thumb_settings\" >";
  7997. $DSP->body .= "<legend>&nbsp;<b>".$LANG->line('file_type')."</b>&nbsp;</legend>";
  7998. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'embed', 1).NBS.$LANG->line('embedded'));
  7999. $DSP->body .= $DSP->qdiv('', $DSP->input_radio('style', 'url', '').NBS.$LANG->line('url_only'));
  8000. $DSP->body .= "</fieldset>";
  8001. }
  8002. $DSP->body .= BR."<fieldset class='thumb' name=\"thumb_settings\" id=\"thumb_settings\" >";
  8003. $DSP->body .= "<legend>&nbsp;<b>".$LANG->line('image_location')."</b>&nbsp;</legend>";
  8004. $i = 1;
  8005. $DSP->body .= $DSP->input_select_header('which');
  8006. foreach ($query->result as $row)
  8007. {
  8008. $DSP->body .= $DSP->input_select_option('field_id_'.$row['field_id'], $row['field_label'], ($i == 1) ? 1 : 0);
  8009. $i++;
  8010. }
  8011. $DSP->body .= $DSP->input_select_footer();
  8012. $DSP->body .= "</fieldset>";
  8013. $line = ($data['is_image'] == 1) ? 'place_image' : 'place_file';
  8014. $DSP->body .= $DSP->div('itemWrapper');
  8015. $DSP->body .= BR."<input type='submit' value='".$LANG->line($line)."' onclick='return fileplacer();' class='submit' />";
  8016. $DSP->body .= NBS.NBS.NBS."<input type='submit' value='".$LANG->line($line.'_close')."' onclick='fileplacer();window.close();' class='submit' />";
  8017. $DSP->body .= $DSP->div_c();
  8018. $DSP->body .= $DSP->qdiv('smallLinks', '');
  8019. $DSP->body .= $DSP->div_c();
  8020. $DSP->body .= $DSP->qdiv('itemWrapper', BR.'<div align="center"><a href="JavaScript:window.close();">'.$LANG->line('close_window').'</a></div>');
  8021. $DSP->body .= $DSP->form_close();
  8022. }
  8023. /* END */
  8024. /** ---------------------------------------------
  8025. /** Fetch HTML Glossary
  8026. /** ----------------------------------------------*/
  8027. function fetch_glossary($field_id)
  8028. {
  8029. global $DSP, $LANG;
  8030. $r = '';
  8031. if (count($this->glossary) == 0)
  8032. {
  8033. $is_glossary = TRUE;
  8034. if ( ! @include_once(PATH_LIB.'glossary.php'))
  8035. {
  8036. $is_glossary = FALSE;
  8037. }
  8038. if ( ! isset($glossary) OR ! is_array($glossary))
  8039. {
  8040. $is_glossary = FALSE;
  8041. }
  8042. if ($is_glossary == FALSE)
  8043. {
  8044. $r .= '<div class="markupWrapper">';
  8045. $r .= $DSP->qdiv('highlight', $LANG->line('no_glossary'));
  8046. $r .= '</div>';
  8047. return $r;
  8048. }
  8049. $this->glossary = $glossary;
  8050. }
  8051. $ckey = 0;
  8052. $rows = count($this->glossary);
  8053. $crow = 0;
  8054. $td_width = round(100/$rows);
  8055. $r .= "<table class='clusterBox' border='0' cellpadding='0' cellspacing='0' width='99%'><tr>";
  8056. foreach ($this->glossary as $key => $val)
  8057. {
  8058. $end = FALSE;
  8059. $end2 = FALSE;
  8060. if ($ckey != $key)
  8061. {
  8062. $r .= '<td class="publishItemWrapper" width="'.$td_width.'%" valign="top">';
  8063. $ckey = $key;
  8064. $end = TRUE;
  8065. $crow++;
  8066. if ($crow < $rows)
  8067. {
  8068. $r .= '<div class="clusterLineR">';
  8069. $end2 = TRUE;
  8070. }
  8071. }
  8072. foreach ($val as $k => $v)
  8073. {
  8074. $link = "onclick='glossaryInsert(this, \"".$field_id."\", \"".htmlspecialchars(addslashes($v['1']))."\")'";
  8075. $line = ( ! $LANG->line($v['0'])) ? ucwords(str_replace(' ', '&nbsp;', str_replace('_', ' ', $v['0']))) : $LANG->line($v['0']);
  8076. $r .= $DSP->qdiv('publishSmPad', $DSP->qdiv('lightLinks', '<a href="javascript:void(0);" '.$link.'>'.$line.'</a>'));
  8077. }
  8078. if ($end == TRUE)
  8079. {
  8080. if ($end2 == TRUE)
  8081. {
  8082. $r .= '</div>';
  8083. $end2 = FALSE;
  8084. }
  8085. $r .= '</td>';
  8086. $end = FALSE;
  8087. }
  8088. }
  8089. $r .= '</tr></table>';
  8090. return $r;
  8091. }
  8092. /* END */
  8093. /** ---------------------------------------------
  8094. /** Fetch Emoticons
  8095. /** ----------------------------------------------*/
  8096. function fetch_emoticons($field_id)
  8097. {
  8098. global $IN, $DSP, $PREFS, $LANG;
  8099. if ( ! is_file(PATH_MOD.'emoticon/emoticons'.EXT))
  8100. {
  8101. return $DSP->qdiv('highlight', BR.$LANG->line('no_smileys'));
  8102. }
  8103. if ($this->smileys === FALSE OR count($this->smileys) == 0)
  8104. {
  8105. include_once PATH_MOD.'emoticon/emoticons'.EXT;
  8106. if ( ! isset($smileys) OR ! is_array($smileys))
  8107. {
  8108. return $DSP->qdiv('highlight', BR.$LANG->line('no_smileys'));
  8109. }
  8110. $this->smileys = $smileys;
  8111. }
  8112. $path = $PREFS->ini('emoticon_path', 1);
  8113. $r = $DSP->table('', '0', '4', '100%');
  8114. $i = 1;
  8115. $dups = array();
  8116. foreach ($this->smileys as $key => $val)
  8117. {
  8118. if ($i == 1)
  8119. {
  8120. $r .= "<tr>\n";
  8121. }
  8122. if (in_array($this->smileys[$key]['0'], $dups))
  8123. continue;
  8124. $r .= "<td><a href=\"#\" onclick=\"return add_smiley('".$key."', '".$field_id."');\"><img src=\"".$path.$this->smileys[$key]['0']."\" width=\"".$this->smileys[$key]['1']."\" height=\"".$this->smileys[$key]['2']."\" title=\"".$this->smileys[$key]['3']."\" alt=\"".$this->smileys[$key]['3']."\" border=\"0\" /></a></td>\n";
  8125. $dups[] = $this->smileys[$key]['0'];
  8126. if ($i == 8)
  8127. {
  8128. $r .= "</tr>\n";
  8129. $i = 1;
  8130. }
  8131. else
  8132. {
  8133. $i++;
  8134. }
  8135. }
  8136. $r = rtrim($r);
  8137. if (substr($r, -5) != "</tr>")
  8138. {
  8139. $r .= "</tr>\n";
  8140. }
  8141. $r .= $DSP->table_c();
  8142. return $r;
  8143. }
  8144. /* END */
  8145. /** ---------------------------------------
  8146. /** View trackbacks
  8147. /** ---------------------------------------*/
  8148. function view_trackbacks($weblog_id = '', $entry_id = '', $message = '')
  8149. {
  8150. global $EXT;
  8151. // -------------------------------------------
  8152. // 'view_trackbacks_start' hook.
  8153. // - Allows complete rewrite of View Trackbacks page.
  8154. //
  8155. $edata = $EXT->call_extension('view_trackbacks_start', $weblog_id, $entry_id, $message);
  8156. if ($EXT->end_script === TRUE) return;
  8157. //
  8158. // -------------------------------------------
  8159. $this->view_comments($weblog_id, $entry_id, $message, TRUE);
  8160. }
  8161. /** ---------------------------------------
  8162. /** View comments and trackback
  8163. /** ---------------------------------------*/
  8164. function view_comments($weblog_id = '', $entry_id = '', $message = '', $show_trackbacks=FALSE, $id_array='', $pagination_links = '', $rownum='')
  8165. {
  8166. global $IN, $DSP, $SESS, $DB, $DSP, $FNS, $LANG, $LOC, $PREFS, $EXT;
  8167. // -------------------------------------------
  8168. // 'view_comments_start' hook.
  8169. // - Allows complete rewrite of View Comments/Trackbacks page.
  8170. //
  8171. $edata = $EXT->call_extension('view_comments_start', $weblog_id, $entry_id, $message, $show_trackbacks, $id_array, $pagination_links, $rownum);
  8172. if ($EXT->end_script === TRUE) return;
  8173. //
  8174. // -------------------------------------------
  8175. $page_next = '';
  8176. $page_previous = '';
  8177. $current_page = 0;
  8178. $t_current_page = '';
  8179. $total_pages = 1;
  8180. $limit = 75;
  8181. /* -------------------------------------------
  8182. /* Hidden Configuration Variables
  8183. /* - view_comment_chars => Number of characters to display (#)
  8184. /* - view_comment_leave_breaks => Create <br />'s based on line breaks? (y/n)
  8185. /* -------------------------------------------*/
  8186. $this->comment_chars = ($PREFS->ini('view_comment_chars') !== FALSE) ? $PREFS->ini('view_comment_chars') : $this->comment_chars;
  8187. $this->comment_leave_breaks = ($PREFS->ini('view_comment_leave_breaks') !== FALSE) ? $PREFS->ini('view_comment_leave_breaks') : $this->comment_leave_breaks;
  8188. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  8189. /** ---------------------------------------
  8190. /** Assign page header and breadcrumb
  8191. /** ---------------------------------------*/
  8192. $DSP->title = ($show_trackbacks === TRUE) ? $LANG->line('trackbacks') : $LANG->line('comments');
  8193. $DSP->crumb = ($show_trackbacks === TRUE) ? $LANG->line('trackbacks') : $LANG->line('comments');
  8194. $r = $DSP->qdiv('tableHeading', ($show_trackbacks === TRUE) ? $LANG->line('trackbacks') : $LANG->line('comments'));
  8195. $validate = ($IN->GBL('validate', 'GET') == 1) ? TRUE : FALSE;
  8196. if ($validate OR (is_array($id_array) && $show_trackbacks === FALSE))
  8197. {
  8198. if ( ! $DSP->allowed_group('can_moderate_comments'))
  8199. {
  8200. return $DSP->no_access_message();
  8201. }
  8202. if (is_array($id_array))
  8203. {
  8204. $validate = TRUE;
  8205. $r = $DSP->qdiv('tableHeading', $LANG->line('comments').' - '.$LANG->line('search'));
  8206. $sql = "SELECT exp_comments.*, exp_weblogs.blog_name, exp_weblog_titles.title as entry_title
  8207. FROM exp_comments, exp_weblogs, exp_weblog_titles
  8208. WHERE exp_comments.comment_id IN ('".implode("','",$id_array)."')
  8209. AND exp_comments.entry_id = exp_weblog_titles.entry_id
  8210. AND exp_comments.weblog_id = exp_weblogs.weblog_id ";
  8211. }
  8212. else
  8213. {
  8214. $sql = "SELECT exp_comments.*, exp_weblogs.blog_name, exp_weblog_titles.title as entry_title
  8215. FROM exp_comments, exp_weblogs, exp_weblog_titles
  8216. WHERE exp_comments.status = 'c'
  8217. AND exp_comments.entry_id = exp_weblog_titles.entry_id
  8218. AND exp_comments.weblog_id = exp_weblogs.weblog_id ";
  8219. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  8220. }
  8221. $sql .= "ORDER BY comment_date DESC LIMIT 0,250";
  8222. $query = $DB->query($sql);
  8223. if ($query->num_rows == 0)
  8224. {
  8225. if ($IN->GBL('U', 'GET') == 1)
  8226. {
  8227. $r .= $DSP->qdiv('success',$LANG->line('status_changed'));
  8228. }
  8229. else
  8230. {
  8231. $r .= $DSP->qdiv('', $LANG->line('no_entries_matching_that_criteria'));
  8232. }
  8233. return $r;
  8234. }
  8235. $comment_text_formatting = 'xhtml';
  8236. $comment_html_formatting = 'safe';
  8237. $comment_allow_img_urls = 'n';
  8238. $comment_auto_link_urls = 'y';
  8239. $i = 0;
  8240. foreach ($query->result as $row)
  8241. {
  8242. $results['c'.$row['comment_id']] = $query->result[$i];
  8243. $i++;
  8244. }
  8245. }
  8246. elseif(is_array($id_array) && $show_trackbacks === TRUE)
  8247. {
  8248. $validate = TRUE;
  8249. $r = $DSP->qdiv('tableHeading', $LANG->line('trackbacks').' - '.$LANG->line('search'));
  8250. $sql = "SELECT exp_trackbacks.*, exp_weblogs.blog_name, exp_weblog_titles.title as entry_title
  8251. FROM exp_trackbacks, exp_weblogs, exp_weblog_titles
  8252. WHERE exp_trackbacks.trackback_id IN ('".implode("','",$id_array)."')
  8253. AND exp_trackbacks.entry_id = exp_weblog_titles.entry_id
  8254. AND exp_trackbacks.weblog_id = exp_weblogs.weblog_id ";
  8255. $query = $DB->query($sql);
  8256. if ($query->num_rows == 0)
  8257. {
  8258. $r .= $DSP->qdiv('', $LANG->line('no_entries_matching_that_criteria'));
  8259. return $r;
  8260. }
  8261. $comment_text_formatting = 'xhtml';
  8262. $comment_html_formatting = 'safe';
  8263. $comment_allow_img_urls = 'n';
  8264. $comment_auto_link_urls = 'y';
  8265. $i = 0;
  8266. foreach ($query->result as $row)
  8267. {
  8268. $results['t'.$row['trackback_id']] = $query->result[$i];
  8269. $i++;
  8270. }
  8271. }
  8272. else
  8273. {
  8274. if ($entry_id == '')
  8275. {
  8276. if ( ! $entry_id = $IN->GBL('entry_id', 'GET'))
  8277. {
  8278. return false;
  8279. }
  8280. }
  8281. if ($weblog_id == '')
  8282. {
  8283. if ( ! $weblog_id = $IN->GBL('weblog_id', 'GET'))
  8284. {
  8285. return false;
  8286. }
  8287. }
  8288. if (USER_BLOG !== FALSE)
  8289. {
  8290. if ($weblog_id != UB_BLOG_ID)
  8291. {
  8292. return false;
  8293. }
  8294. }
  8295. if ( ! is_numeric($entry_id) OR ! is_numeric($weblog_id))
  8296. {
  8297. return FALSE;
  8298. }
  8299. /** ---------------------------------------
  8300. /** Fetch Author ID and verify privs
  8301. /** ---------------------------------------*/
  8302. $query = $DB->query("SELECT author_id, title FROM exp_weblog_titles WHERE entry_id = '$entry_id'");
  8303. if ($query->num_rows == 0)
  8304. {
  8305. return $DSP->error_message($LANG->line('no_weblog_exits'));
  8306. }
  8307. if ($query->row['author_id'] != $SESS->userdata('member_id'))
  8308. {
  8309. if ( ! $DSP->allowed_group('can_view_other_comments'))
  8310. {
  8311. return $DSP->no_access_message();
  8312. }
  8313. }
  8314. $et = $query->row['title'];
  8315. $r = $DSP->qdiv('tableHeading', (($show_trackbacks === TRUE) ? $LANG->line('trackbacks') : $LANG->line('comments')).' - '.$et);
  8316. //---------------------------------------
  8317. // Fetch comment display preferences
  8318. // Also used for displaying trackbacks, so
  8319. // we leave it in here - Paul
  8320. //---------------------------------------
  8321. $query = $DB->query("SELECT comment_text_formatting,
  8322. comment_html_formatting,
  8323. comment_allow_img_urls,
  8324. comment_auto_link_urls
  8325. FROM exp_weblogs
  8326. WHERE weblog_id = '$weblog_id'");
  8327. if ($query->num_rows == 0)
  8328. {
  8329. return $DSP->error_message($LANG->line('no_weblog_exits'));
  8330. }
  8331. foreach ($query->row as $key => $val)
  8332. {
  8333. $$key = $val;
  8334. }
  8335. /** ----------------------------------------
  8336. /** Fetch comment ID numbers
  8337. /** ----------------------------------------*/
  8338. $temp = array();
  8339. $i = 0;
  8340. $comments_exist = FALSE;
  8341. if ($show_trackbacks === FALSE)
  8342. {
  8343. $query = $DB->query("SELECT comment_date, comment_id FROM exp_comments WHERE entry_id = '$entry_id' ORDER BY comment_date");
  8344. if ($query->num_rows > 0)
  8345. {
  8346. $comments_exist = TRUE;
  8347. foreach ($query->result as $row)
  8348. {
  8349. $i++;
  8350. $temp[$row['comment_date'].$i] = 'c'.$row['comment_id'];
  8351. }
  8352. }
  8353. }
  8354. /** ----------------------------------------
  8355. /** Fetch trackback ID numbers
  8356. /** ----------------------------------------*/
  8357. $trackbacks_exist = FALSE;
  8358. if ($show_trackbacks === TRUE)
  8359. {
  8360. $query = $DB->query("SELECT trackback_date, trackback_id FROM exp_trackbacks WHERE entry_id = '$entry_id' ORDER BY trackback_date");
  8361. if ($query->num_rows > 0)
  8362. {
  8363. $trackbacks_exist = TRUE;
  8364. foreach ($query->result as $row)
  8365. {
  8366. $i++;
  8367. $temp[$row['trackback_date'].$i] = 't'.$row['trackback_id'];
  8368. }
  8369. }
  8370. }
  8371. /** ------------------------------------
  8372. /** No results? No reason to continue...
  8373. /** ------------------------------------*/
  8374. if (count($temp) == 0)
  8375. {
  8376. return $DSP->body = $DSP->qdiv('', $LANG->line('no_comments_or_trackbacks'));
  8377. }
  8378. // Sort the array based on the keys (which contain the Unix timesamps
  8379. // of the comments and trackbacks)
  8380. ksort($temp);
  8381. // Create a new, sequentially indexed array
  8382. $result_ids = array();
  8383. foreach ($temp as $val)
  8384. {
  8385. $result_ids[$val] = $val;
  8386. }
  8387. // $result_ids = array_reverse($result_ids);
  8388. /** ---------------------------------
  8389. /** Do we need pagination?
  8390. /** ---------------------------------*/
  8391. if ($IN->GBL('current_page'))
  8392. {
  8393. $current_page = $IN->GBL('current_page');
  8394. }
  8395. $total_rows = count($result_ids);
  8396. $current_page = ($current_page == '' || ($limit > 1 AND $current_page == 1)) ? 0 : $current_page;
  8397. if ($current_page > $total_rows)
  8398. {
  8399. $current_page = 0;
  8400. }
  8401. $t_current_page = floor(($current_page / $limit) + 1);
  8402. $total_pages = intval(floor($total_rows / $limit));
  8403. if ($total_rows % $limit)
  8404. $total_pages++;
  8405. if ($total_rows > $limit)
  8406. {
  8407. if ( ! class_exists('Paginate'))
  8408. {
  8409. require PATH_CORE.'core.paginate'.EXT;
  8410. }
  8411. $PGR = new Paginate();
  8412. if ($show_trackbacks === FALSE)
  8413. {
  8414. $basepath = BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id;
  8415. }
  8416. else
  8417. {
  8418. $basepath = BASE.AMP.'C=edit'.AMP.'M=view_trackbacks'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id;
  8419. }
  8420. $pagination_links = $DSP->pager( $basepath,
  8421. $total_rows,
  8422. $limit,
  8423. $current_page,
  8424. 'current_page'
  8425. );
  8426. if ((($total_pages * $limit) - $limit) > $current_page)
  8427. {
  8428. $page_next = $basepath.'P'.($current_page + $limit).'/';
  8429. }
  8430. if (($current_page - $limit ) >= 0)
  8431. {
  8432. $page_previous = $basepath.'P'.($current_page - $limit).'/';
  8433. }
  8434. }
  8435. if ($current_page == '')
  8436. {
  8437. $result_ids = array_slice($result_ids, 0, $limit);
  8438. }
  8439. else
  8440. {
  8441. $result_ids = array_slice($result_ids, $current_page, $limit);
  8442. }
  8443. /** -----------------------------------
  8444. /** Fetch Comments if necessary
  8445. /** -----------------------------------*/
  8446. $results = $result_ids;
  8447. if ($comments_exist == TRUE)
  8448. {
  8449. $com = '';
  8450. foreach ($result_ids as $val)
  8451. {
  8452. if (substr($val, 0, 1) == 'c')
  8453. {
  8454. $com .= substr($val, 1).",";
  8455. }
  8456. }
  8457. if ($com != '')
  8458. {
  8459. $sql = "SELECT
  8460. exp_comments.comment_id, exp_comments.entry_id, exp_comments.status, exp_comments.weblog_id, exp_comments.author_id, exp_comments.name, exp_comments.email, exp_comments.url, exp_comments.location, exp_comments.ip_address, exp_comments.comment_date, exp_comments.comment
  8461. FROM exp_comments
  8462. WHERE exp_comments.comment_id IN (".substr($com, 0, -1).")";
  8463. $query = $DB->query($sql);
  8464. if ($query->num_rows > 0)
  8465. {
  8466. $i = 0;
  8467. foreach ($query->result as $row)
  8468. {
  8469. if (isset($results['c'.$row['comment_id']]))
  8470. {
  8471. $results['c'.$row['comment_id']] = $query->result[$i];
  8472. $i++;
  8473. }
  8474. }
  8475. }
  8476. }
  8477. }
  8478. /** -----------------------------------
  8479. /** Fetch Trackbacks if necessary
  8480. /** -----------------------------------*/
  8481. if ($trackbacks_exist == TRUE)
  8482. {
  8483. $trb = '';
  8484. foreach ($result_ids as $val)
  8485. {
  8486. if (substr($val, 0, 1) == 't')
  8487. {
  8488. $trb .= substr($val, 1).",";
  8489. }
  8490. }
  8491. if ($trb != '')
  8492. {
  8493. $sql = "SELECT exp_trackbacks.* FROM exp_trackbacks
  8494. WHERE exp_trackbacks.trackback_id IN (".substr($trb, 0, -1).")";
  8495. $query = $DB->query($sql);
  8496. if ($query->num_rows > 0)
  8497. {
  8498. $i = 0;
  8499. foreach ($query->result as $row)
  8500. {
  8501. if (isset($results['t'.$row['trackback_id']]))
  8502. {
  8503. $results['t'.$row['trackback_id']] = $query->result[$i];
  8504. $i++;
  8505. }
  8506. }
  8507. }
  8508. }
  8509. }
  8510. // END IF VALIDATE
  8511. }
  8512. if ($message != '')
  8513. $r .= $DSP->qdiv('box', $message);
  8514. /** ---------------------------------------
  8515. /** Instantiate the Typography class
  8516. /** ---------------------------------------*/
  8517. if ( ! class_exists('Typography'))
  8518. {
  8519. require PATH_CORE.'core.typography'.EXT;
  8520. }
  8521. $TYPE = new Typography;
  8522. $val = ($validate) ? AMP.'validate=1' : '';
  8523. /** ---------------------------------------
  8524. /** Create Table Header
  8525. /** ---------------------------------------*/
  8526. $r .= $DSP->toggle();
  8527. $DSP->body_props .= ' onload="magic_check()" ';
  8528. $r .= $DSP->magic_checkboxes();
  8529. $r .= $DSP->form_open(
  8530. array(
  8531. 'action' => 'C=edit'.AMP.'M=modify_comments',
  8532. 'name' => 'target',
  8533. 'id' => 'target'
  8534. )
  8535. );
  8536. $r .= $DSP->input_hidden('current_page', $rownum);
  8537. if ($IN->GBL('keywords') !== FALSE)
  8538. {
  8539. $r .= $DSP->input_hidden('keywords', $IN->GBL('keywords'));
  8540. }
  8541. if ($show_trackbacks === TRUE)
  8542. {
  8543. $r .= $DSP->table('tableBorder', '0', '', '100%').
  8544. $DSP->tr().
  8545. $DSP->table_qcell('tableHeadingAlt', $LANG->line('title')).
  8546. $DSP->table_qcell('tableHeadingAlt', $LANG->line('weblog')).
  8547. $DSP->table_qcell('tableHeadingAlt', $LANG->line('date')).
  8548. $DSP->table_qcell('tableHeadingAlt', $LANG->line('comment_ip')).
  8549. $DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").NBS.$LANG->line('action')).
  8550. $DSP->tr_c();
  8551. }
  8552. else
  8553. {
  8554. $r .= $DSP->table('tableBorder', '0', '', '100%').
  8555. $DSP->tr().
  8556. $DSP->table_qcell('tableHeadingAlt', $LANG->line('comment')).
  8557. (($validate === TRUE) ? $DSP->table_qcell('tableHeadingAlt', $LANG->line('weblog')) : '').
  8558. (($validate === TRUE) ? $DSP->table_qcell('tableHeadingAlt', $LANG->line('view_entry')) : '').
  8559. $DSP->table_qcell('tableHeadingAlt', $LANG->line('author')).
  8560. $DSP->table_qcell('tableHeadingAlt', $LANG->line('email')).
  8561. $DSP->table_qcell('tableHeadingAlt', $LANG->line('date')).
  8562. $DSP->table_qcell('tableHeadingAlt', $LANG->line('comment_ip')).
  8563. $DSP->table_qcell('tableHeadingAlt', $LANG->line('status')).
  8564. $DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").NBS.$LANG->line('action')).
  8565. $DSP->tr_c();
  8566. }
  8567. /** -------------------------------
  8568. /** Show comments
  8569. /** -------------------------------*/
  8570. $comment_flag = FALSE;
  8571. $trackback_flag = FALSE;
  8572. foreach ($results as $id => $row)
  8573. {
  8574. if ( ! is_array($row))
  8575. continue;
  8576. /** -------------------------------
  8577. /** Show Comments
  8578. /** -------------------------------*/
  8579. if (substr($id, 0, 1) == 'c')
  8580. {
  8581. $comment_flag = TRUE;
  8582. if ($this->comment_leave_breaks == 'y')
  8583. {
  8584. $row['comment'] = str_replace(array("\n","\r"),
  8585. '<br />',
  8586. strip_tags($row['comment'])
  8587. );
  8588. }
  8589. else
  8590. {
  8591. $row['comment'] = strip_tags(str_replace(array("\t","\n","\r"), '', $row['comment']));
  8592. }
  8593. if ($this->comment_chars != 0)
  8594. {
  8595. $row['comment'] = $FNS->char_limiter(trim($row['comment']), $this->comment_chars);
  8596. }
  8597. if (is_array($id_array))
  8598. {
  8599. $edit_comment = $DSP->anchor(BASE.AMP.'C=edit'.
  8600. AMP.'M=edit_comment'.
  8601. AMP.'weblog_id='.$row['weblog_id'].
  8602. AMP.'keywords='.$IN->GBL('keywords').
  8603. AMP.'entry_id='.$row['entry_id'].
  8604. AMP.'comment_id='.$row['comment_id'].
  8605. AMP.'current_page='.$rownum.$val,
  8606. $row['comment']);
  8607. }
  8608. else
  8609. {
  8610. $edit_comment = $DSP->anchor(BASE.AMP.'C=edit'.
  8611. AMP.'M=edit_comment'.
  8612. AMP.'weblog_id='.$row['weblog_id'].
  8613. AMP.'entry_id='.$row['entry_id'].
  8614. AMP.'comment_id='.$row['comment_id'].
  8615. AMP.'current_page='.$current_page.$val,
  8616. $row['comment']);
  8617. }
  8618. $r .= $DSP->tr()
  8619. . $DSP->td('tableCellTwo')
  8620. . $edit_comment
  8621. . $DSP->td_c();
  8622. if ($validate === TRUE)
  8623. {
  8624. // Weblog entry title (view entry)
  8625. $show_link = TRUE;
  8626. if (($row['author_id'] != $SESS->userdata('member_id')) && ! $DSP->allowed_group('can_edit_other_entries'))
  8627. {
  8628. $show_link = FALSE;
  8629. }
  8630. $entry_url = BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'];
  8631. $entry_title = $FNS->char_limiter(trim(strip_tags($row['entry_title'])), 26); // Paul's Age!
  8632. $r .= $DSP->td('tableCellTwo')
  8633. . $row['blog_name']
  8634. . $DSP->td_c()
  8635. . $DSP->td('tableCellTwo')
  8636. . (($show_link == FALSE) ? $entry_title : $DSP->anchor($entry_url, $entry_title))
  8637. . $DSP->td_c();
  8638. }
  8639. if ($row['author_id'] == '0')
  8640. {
  8641. $mid_search = $row['name'];
  8642. }
  8643. else
  8644. {
  8645. $mid_search = $DSP->anchor(BASE.AMP.'C=edit'.
  8646. AMP.'M=view_entries'.
  8647. AMP.'search_in=comments'.
  8648. AMP.'order=desc'.
  8649. AMP.'keywords='.base64_encode('mid:'.$row['author_id']),
  8650. $row['name']);
  8651. }
  8652. $r .= $DSP->td('tableCellTwo')
  8653. . $mid_search
  8654. . $DSP->td_c();
  8655. $email = ($row['email'] != '') ? $DSP->mailto($row['email'], $row['email']) : NBS.'--'.NBS;
  8656. $r .= $DSP->td('tableCellTwo')
  8657. . $email
  8658. . $DSP->td_c();
  8659. if ($row['status'] == 'o')
  8660. {
  8661. $status = 'close';
  8662. $status_label = $LANG->line('open');
  8663. }
  8664. else
  8665. {
  8666. $status = 'open';
  8667. $status_label = $LANG->line('closed');
  8668. }
  8669. if (is_array($id_array))
  8670. {
  8671. $status_change = $DSP->anchor(BASE.AMP.'C=edit'.
  8672. AMP.'M=change_status'.
  8673. AMP.'search_in=comments'.
  8674. AMP.'weblog_id='.$row['weblog_id'].
  8675. AMP.'keywords='.$IN->GBL('keywords').
  8676. AMP.'comment_id='.$row['comment_id'].
  8677. AMP.'current_page='.$rownum.
  8678. AMP.'status='.$status.$val, $status_label);
  8679. }
  8680. else
  8681. {
  8682. $status_change = $DSP->anchor(BASE.AMP.'C=edit'.
  8683. AMP.'M=change_status'.
  8684. AMP.'weblog_id='.$weblog_id.
  8685. AMP.'entry_id='.$entry_id.
  8686. AMP.'comment_id='.$row['comment_id'].
  8687. AMP.'current_page='.$current_page.
  8688. AMP.'status='.$status.$val, $status_label);
  8689. }
  8690. $ip_search = $DSP->anchor(BASE.AMP.'C=edit'.
  8691. AMP.'M=view_entries'.
  8692. AMP.'search_in=comments'.
  8693. AMP.'order=desc'.
  8694. AMP.'keywords='.base64_encode('ip:'.str_replace('.','_',$row['ip_address'])),
  8695. $row['ip_address']);
  8696. $r .= $DSP->td('tableCellTwo')
  8697. . $LOC->set_human_time($row['comment_date'])
  8698. . $DSP->td_c()
  8699. . $DSP->td('tableCellTwo')
  8700. . $ip_search
  8701. . $DSP->td_c()
  8702. . $DSP->td('tableCellTwo')
  8703. . $status_change
  8704. . $DSP->td_c()
  8705. . $DSP->td('tableCellTwo')
  8706. . $DSP->input_checkbox('toggle[]', $id, '', "id='delete_box_{$id}'")
  8707. . $DSP->td_c()
  8708. .$DSP->tr_c();
  8709. }
  8710. /** -------------------------------
  8711. /** Show Trackbacks
  8712. /** -------------------------------*/
  8713. elseif (substr($id, 0, 1) == 't')
  8714. {
  8715. $trackback_flag = TRUE;
  8716. $ip_search = $DSP->anchor(BASE.AMP.'C=edit'.
  8717. AMP.'M=view_entries'.
  8718. AMP.'search_in=trackbacks'.
  8719. AMP.'order=desc'.
  8720. AMP.'keywords='.base64_encode('ip:'.str_replace('.','_',$row['trackback_ip'])),
  8721. $row['trackback_ip']);
  8722. $r .= $DSP->tr()
  8723. . $DSP->td('tableCellTwo')
  8724. . $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=edit_trackback'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'].AMP.'trackback_id='.$row['trackback_id'], $row['title'])
  8725. . $DSP->td_c()
  8726. . $DSP->td('tableCellTwo')
  8727. . $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.$row['trackback_url'], $row['weblog_name'])
  8728. . $DSP->td_c()
  8729. . $DSP->td('tableCellTwo')
  8730. . '<nobr>'.$LOC->set_human_time($row['trackback_date']).'</nobr>'
  8731. . $DSP->td_c()
  8732. . $DSP->td('tableCellTwo')
  8733. . $ip_search
  8734. . $DSP->td_c()
  8735. . $DSP->td('tableCellTwo')
  8736. . $DSP->input_checkbox('toggle[]', $id, '', "id='delete_box_{$id}'")
  8737. . $DSP->td_c()
  8738. . $DSP->tr_c();
  8739. }
  8740. }
  8741. // END FOREACH
  8742. if ($comment_flag === FALSE && $trackback_flag === TRUE)
  8743. {
  8744. $options = $DSP->input_select_header('action').
  8745. $DSP->input_select_option('delete', $LANG->line('delete_selected')).
  8746. $DSP->input_select_footer();
  8747. }
  8748. else
  8749. {
  8750. $options = $DSP->input_select_header('action').
  8751. $DSP->input_select_option('close', $LANG->line('close_selected')).
  8752. $DSP->input_select_option('open', $LANG->line('open_selected')).
  8753. $DSP->input_select_option('delete', $LANG->line('delete_selected'));
  8754. if ( $DSP->allowed_group('can_edit_all_comments') OR
  8755. $DSP->allowed_group('can_moderate_comments'))
  8756. {
  8757. $options .= $DSP->input_select_option('null', '------').
  8758. $DSP->input_select_option('move', $LANG->line('move_selected'));
  8759. }
  8760. $options .= $DSP->input_select_footer();
  8761. }
  8762. $r .= $DSP->table_c();
  8763. $r .= $DSP->table('', '0', '', '100%')
  8764. . $DSP->tr()
  8765. . $DSP->td('defaultRight')
  8766. . $DSP->input_submit($LANG->line('submit')).NBS.NBS.$options
  8767. . $DSP->td_c()
  8768. . $DSP->tr_c()
  8769. . $DSP->table_c()
  8770. .$DSP->form_close();
  8771. if ($pagination_links != '')
  8772. {
  8773. $r .= $DSP->qdiv('itemWrapper', $pagination_links);
  8774. }
  8775. $DSP->body = $r;
  8776. }
  8777. /* END */
  8778. /** -----------------------------------------
  8779. /** Move comments form
  8780. /** -----------------------------------------*/
  8781. function move_comments_form()
  8782. {
  8783. global $IN, $DSP, $DB, $LANG, $PREFS, $REGX, $FNS, $SESS, $STAT;
  8784. $weblog_id = $IN->GBL('weblog_id');
  8785. $entry_id = $IN->GBL('entry_id');
  8786. if($IN->GBL('comment_ids') !== FALSE)
  8787. {
  8788. $comments = explode('|', $IN->GBL('comment_ids'));
  8789. foreach($comments as $key => $val)
  8790. {
  8791. $comments[$key] = $DB->escape_str($val);
  8792. }
  8793. }
  8794. else
  8795. {
  8796. $comments = array();
  8797. foreach ($_POST as $key => $val)
  8798. {
  8799. if (strstr($key, 'toggle') AND ! is_array($val))
  8800. {
  8801. if (substr($val, 0, 1) == 'c')
  8802. {
  8803. $comments[] = $DB->escape_str(substr($val, 1));
  8804. }
  8805. }
  8806. }
  8807. if($IN->GBL('comment_id') !== FALSE && is_numeric($IN->GBL('comment_id')))
  8808. {
  8809. $comments[] = $DB->escape_str($IN->GBL('comment_id'));
  8810. }
  8811. }
  8812. if (sizeof($comments) == 0)
  8813. {
  8814. return $this->edit_entries();
  8815. }
  8816. if ( ! $DSP->allowed_group('can_moderate_comments') && ! $DSP->allowed_group('can_edit_all_comments'))
  8817. {
  8818. return $DSP->no_access_message();
  8819. }
  8820. if ($DSP->allowed_group('can_edit_all_comments'))
  8821. {
  8822. // Can Edit All Comments
  8823. $sql = "SELECT exp_comments.comment_id
  8824. FROM exp_comments
  8825. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')";
  8826. }
  8827. else
  8828. {
  8829. // Can Moderate Comments, but only from non-USER blogs.
  8830. $sql = "SELECT exp_comments.comment_id
  8831. FROM exp_comments, exp_weblogs
  8832. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')
  8833. AND exp_comments.weblog_id = exp_weblogs.weblog_id ";
  8834. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  8835. }
  8836. /** -------------------------------
  8837. /** Retrieve Our Results
  8838. /** -------------------------------*/
  8839. $query = $DB->query($sql);
  8840. if ($query->num_rows == 0)
  8841. {
  8842. return $DSP->no_access_message();
  8843. }
  8844. $comment_ids = array();
  8845. foreach($query->result as $row)
  8846. {
  8847. $comment_ids[] = $row['comment_id'];
  8848. }
  8849. /** -------------------------------
  8850. /** Create Our Form
  8851. /** -------------------------------*/
  8852. $r = $DSP->input_hidden('comment_ids', implode('|', $comments));
  8853. if ($IN->GBL('keywords') !== FALSE)
  8854. {
  8855. $r .= $DSP->input_hidden('keywords', $IN->GBL('keywords'));
  8856. }
  8857. if ($IN->GBL('current_page') !== FALSE)
  8858. {
  8859. $r .= $DSP->input_hidden('current_page', $IN->GBL('current_page'));
  8860. }
  8861. $actions = NBS.$DSP->input_select_header('action').
  8862. $DSP->input_select_option('move', $LANG->line('move_comments_to_entry')).
  8863. $DSP->input_select_footer();
  8864. $DSP->title = $LANG->line('choose_entry_for_comment_move');
  8865. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_comments', $LANG->line('comments')).$DSP->crumb_item($LANG->line('choose_entry_for_comment_move'));
  8866. $DSP->body .= $this->view_entries( '',
  8867. '',
  8868. '',
  8869. 'C=edit'.AMP.'M=move_comments_form',
  8870. 'C=edit'.AMP.'M=move_comments',
  8871. $actions,
  8872. $r,
  8873. $r);
  8874. $DSP->body = preg_replace("/".str_replace('REPLACE_HERE',
  8875. '.*?',
  8876. preg_quote($DSP->qdiv('tableHeading', 'REPLACE_HERE'),
  8877. '/')
  8878. )."/",
  8879. $DSP->qdiv('tableHeading', $LANG->line('choose_entry_for_comment_move')),
  8880. $DSP->body,
  8881. 1);
  8882. }
  8883. /* END */
  8884. /** -----------------------------------------
  8885. /** Moving comments
  8886. /** -----------------------------------------*/
  8887. function move_comments()
  8888. {
  8889. global $IN, $DSP, $DB, $LANG, $PREFS, $REGX, $FNS, $SESS, $STAT;
  8890. $weblog_id = $IN->GBL('weblog_id');
  8891. $entry_id = $IN->GBL('entry_id');
  8892. if ( ! $DSP->allowed_group('can_moderate_comments') && ! $DSP->allowed_group('can_edit_all_comments'))
  8893. {
  8894. return $DSP->no_access_message();
  8895. }
  8896. if($IN->GBL('comment_ids') !== FALSE)
  8897. {
  8898. $comments = explode('|', $IN->GBL('comment_ids'));
  8899. foreach($comments as $key => $val)
  8900. {
  8901. $comments[$key] = $DB->escape_str($val);
  8902. }
  8903. }
  8904. else
  8905. {
  8906. return $this->edit_entries();
  8907. }
  8908. $new_entries = array();
  8909. foreach ($_POST as $key => $val)
  8910. {
  8911. if (strstr($key, 'toggle') AND ! is_array($val))
  8912. {
  8913. $new_entries[] = $val;
  8914. }
  8915. }
  8916. if (sizeof($new_entries) == 0)
  8917. {
  8918. return $this->move_comments_form();
  8919. }
  8920. elseif(sizeof($new_entries) > 1)
  8921. {
  8922. return $DSP->error_message($LANG->line('choose_only_one_entry'));
  8923. }
  8924. $query = $DB->query("SELECT weblog_id, entry_id FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($new_entries['0'])."'");
  8925. $new_entry_id = $query->row['entry_id'];
  8926. $new_weblog_id = $query->row['weblog_id'];
  8927. if ($DSP->allowed_group('can_edit_all_comments'))
  8928. {
  8929. // Can Edit All Comments
  8930. $sql = "SELECT exp_comments.comment_id, exp_comments.weblog_id, exp_comments.entry_id
  8931. FROM exp_comments
  8932. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')";
  8933. }
  8934. else
  8935. {
  8936. // Can Moderate Comments, but only from non-USER blogs.
  8937. $sql = "SELECT exp_comments.comment_id, exp_comments.weblog_id, exp_comments.entry_id
  8938. FROM exp_comments, exp_weblogs
  8939. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')
  8940. AND exp_comments.weblog_id = exp_weblogs.weblog_id ";
  8941. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  8942. }
  8943. /** -------------------------------
  8944. /** Retrieve Our Results
  8945. /** -------------------------------*/
  8946. $query = $DB->query($sql);
  8947. if ($query->num_rows == 0)
  8948. {
  8949. return $DSP->no_access_message();
  8950. }
  8951. $comment_ids = array();
  8952. $entry_ids = array($new_entry_id);
  8953. $weblog_ids = array($new_weblog_id);
  8954. /** -------------------------------
  8955. /** Move Comments
  8956. /** -------------------------------*/
  8957. foreach($query->result as $row)
  8958. {
  8959. $DB->query($DB->update_string('exp_comments', array('weblog_id' => $new_weblog_id, 'entry_id' => $new_entry_id), "comment_id = '".$row['comment_id']."'"));
  8960. $comment_ids[] = $row['comment_id'];
  8961. $entry_ids[] = $row['entry_id'];
  8962. $weblog_ids[] = $row['weblog_id'];
  8963. }
  8964. /** -------------------------------
  8965. /** Recounts
  8966. /** -------------------------------*/
  8967. foreach(array_unique($entry_ids) as $entry_id)
  8968. {
  8969. $query = $DB->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$DB->escape_str($entry_id)."'");
  8970. $comment_date = ($query->num_rows == 0 OR !is_numeric($query->row['max_date'])) ? 0 : $query->row['max_date'];
  8971. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o'");
  8972. $DB->query("UPDATE exp_weblog_titles SET comment_total = '".($query->row['count'])."', recent_comment_date = '$comment_date' WHERE entry_id = '".$DB->escape_str($entry_id)."'");
  8973. }
  8974. // Quicker and updates just the weblogs
  8975. foreach(array_unique($weblog_ids) as $weblog_id) { $STAT->update_comment_stats($weblog_id, '', FALSE); }
  8976. // Updates the total stats
  8977. $STAT->update_comment_stats();
  8978. $FNS->clear_caching('all');
  8979. $FNS->redirect(BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$new_weblog_id.AMP.'entry_id='.$new_entry_id.AMP.'U=1'.$val);
  8980. exit;
  8981. }
  8982. /* END */
  8983. /** -----------------------------------------
  8984. /** Edit comments form
  8985. /** -----------------------------------------*/
  8986. function edit_comment_form()
  8987. {
  8988. global $IN, $DB, $DSP, $LANG, $SESS, $EXT;
  8989. // -------------------------------------------
  8990. // 'edit_comment_form_start' hook.
  8991. // - Allows complete rewrite of Edit Comment page.
  8992. //
  8993. $edata = $EXT->call_extension('edit_comment_form_start');
  8994. if ($EXT->end_script === TRUE) return;
  8995. //
  8996. // -------------------------------------------
  8997. $comment_id = $IN->GBL('comment_id');
  8998. $weblog_id = $IN->GBL('weblog_id');
  8999. $entry_id = $IN->GBL('entry_id');
  9000. $current_page = $IN->GBL('current_page');
  9001. if ($comment_id == FALSE OR ! is_numeric($comment_id) OR ! is_numeric($weblog_id) OR ! is_numeric($entry_id))
  9002. {
  9003. return $DSP->no_access_message();
  9004. }
  9005. $validate = 0;
  9006. if ($IN->GBL('validate') == 1)
  9007. {
  9008. if ( ! $DSP->allowed_group('can_moderate_comments'))
  9009. {
  9010. return $DSP->no_access_message();
  9011. }
  9012. $sql = "SELECT exp_comments.*
  9013. FROM exp_comments, exp_weblogs
  9014. WHERE comment_id = '$comment_id' ";
  9015. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  9016. $query = $DB->query($sql);
  9017. $validate = 1;
  9018. }
  9019. else
  9020. {
  9021. if ( ! $DSP->allowed_group('can_edit_all_comments'))
  9022. {
  9023. if ( ! $DSP->allowed_group('can_edit_own_comments'))
  9024. {
  9025. return $DSP->no_access_message();
  9026. }
  9027. else
  9028. {
  9029. $sql = "SELECT exp_weblog_titles.author_id
  9030. FROM exp_weblog_titles, exp_comments
  9031. WHERE exp_weblog_titles.entry_id = exp_comments.entry_id
  9032. AND exp_comments.comment_id = '$comment_id'";
  9033. $query = $DB->query($sql);
  9034. if ($query->row['author_id'] != $SESS->userdata('member_id'))
  9035. {
  9036. return $DSP->no_access_message();
  9037. }
  9038. }
  9039. }
  9040. $query = $DB->query("SELECT * FROM exp_comments WHERE comment_id = '$comment_id'");
  9041. }
  9042. if ($query->num_rows == 0)
  9043. {
  9044. return false;
  9045. }
  9046. foreach ($query->row as $key => $val)
  9047. {
  9048. $$key = $val;
  9049. }
  9050. $r = $DSP->form_open(array('action' => 'C=edit'.AMP.'M=update_comment'));
  9051. $r .= $DSP->input_hidden('comment_id', $comment_id);
  9052. $r .= $DSP->input_hidden('author_id', $author_id);
  9053. $r .= $DSP->input_hidden('weblog_id', $weblog_id);
  9054. $r .= $DSP->input_hidden('current_page', $current_page);
  9055. $r .= $DSP->input_hidden('entry_id', $entry_id);
  9056. $r .= $DSP->input_hidden('validate', $validate);
  9057. if ($IN->GBL('keywords') !== FALSE)
  9058. {
  9059. $r .= $DSP->input_hidden('keywords', $IN->GBL('keywords'));
  9060. }
  9061. $r .= $DSP->qdiv('tableHeading', $LANG->line('edit_comment'));
  9062. if ($author_id == 0)
  9063. {
  9064. $r .= $DSP->itemgroup(
  9065. $DSP->required().NBS.$LANG->line('name', 'name'),
  9066. $DSP->input_text('name', $name, '40', '100', 'input', '300px')
  9067. );
  9068. $r .= $DSP->itemgroup(
  9069. $DSP->required().NBS.$LANG->line('email', 'email'),
  9070. $DSP->input_text('email', $email, '35', '100', 'input', '300px')
  9071. );
  9072. $r .= $DSP->itemgroup(
  9073. $LANG->line('url', 'url'),
  9074. $DSP->input_text('url', $url, '40', '100', 'input', '300px')
  9075. );
  9076. $r .= $DSP->itemgroup(
  9077. $LANG->line('location', 'location'),
  9078. $DSP->input_text('location', $location, '40', '100', 'input', '300px')
  9079. );
  9080. }
  9081. $r .= $DSP->input_textarea('comment', $comment, '20', 'textarea', '100%');
  9082. // Submit button
  9083. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  9084. $r .= $DSP->form_close();
  9085. $DSP->title = $LANG->line('edit_comment');
  9086. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id, $LANG->line('comments')).$DSP->crumb_item($LANG->line('edit_comment'));
  9087. $DSP->body = $r;
  9088. }
  9089. /* END */
  9090. /** -----------------------------------------
  9091. /** Edit trackbacks form
  9092. /** -----------------------------------------*/
  9093. function edit_trackback_form()
  9094. {
  9095. global $IN, $DB, $DSP, $LANG, $SESS, $EXT;
  9096. // -------------------------------------------
  9097. // 'edit_trackback_form' hook.
  9098. // - Allows complete rewrite of Edit Trackback page.
  9099. //
  9100. $edata = $EXT->call_extension('edit_trackback_form');
  9101. if ($EXT->end_script === TRUE) return;
  9102. //
  9103. // -------------------------------------------
  9104. $trackback_id = $IN->GBL('trackback_id');
  9105. $weblog_id = $IN->GBL('weblog_id');
  9106. $entry_id = $IN->GBL('entry_id');
  9107. $current_page = $IN->GBL('current_page');
  9108. if ($trackback_id == FALSE OR ! is_numeric($trackback_id) OR ! is_numeric($weblog_id) OR ! is_numeric($entry_id))
  9109. {
  9110. return $DSP->no_access_message();
  9111. }
  9112. if ( ! $DSP->allowed_group('can_edit_all_comments'))
  9113. {
  9114. if ( ! $DSP->allowed_group('can_edit_own_comments'))
  9115. {
  9116. return $DSP->no_access_message();
  9117. }
  9118. else
  9119. {
  9120. $sql = "SELECT exp_weblog_titles.author_id
  9121. FROM exp_weblog_titles, exp_trackbacks
  9122. WHERE exp_weblog_titles.entry_id = exp_trackbacks.entry_id
  9123. AND exp_trackbacks.trackback_id = '$trackback_id'";
  9124. $query = $DB->query($sql);
  9125. if ($query->row['author_id'] != $SESS->userdata('member_id'))
  9126. {
  9127. return $DSP->no_access_message();
  9128. }
  9129. }
  9130. }
  9131. $query = $DB->query("SELECT * FROM exp_trackbacks WHERE trackback_id = '$trackback_id'");
  9132. if ($query->num_rows == 0)
  9133. {
  9134. return false;
  9135. }
  9136. foreach ($query->row as $key => $val)
  9137. {
  9138. $$key = $val;
  9139. }
  9140. $r = $DSP->form_open(array('action' => 'C=edit'.AMP.'M=update_trackback'));
  9141. $r .= $DSP->input_hidden('trackback_id', $trackback_id);
  9142. $r .= $DSP->input_hidden('weblog_id', $weblog_id);
  9143. $r .= $DSP->input_hidden('current_page', $current_page);
  9144. $r .= $DSP->input_hidden('entry_id', $entry_id);
  9145. $r .= $DSP->qdiv('tableHeading', $LANG->line('edit_trackback'));
  9146. $r .= $DSP->itemgroup(
  9147. $DSP->required().NBS.$LANG->line('title', 'title'),
  9148. $DSP->input_text('title', $title, '40', '100', 'input', '300px')
  9149. );
  9150. $r .= $DSP->itemgroup(
  9151. $DSP->required().NBS.$LANG->line('weblog', 'weblog'),
  9152. $DSP->input_text('weblog', $weblog_name, '50', '100', 'input', '300px')
  9153. );
  9154. $r .= $DSP->itemgroup(
  9155. $DSP->required().NBS.$LANG->line('url', 'url'),
  9156. $DSP->input_text('url', $trackback_url, '50', '125', 'input', '300px')
  9157. );
  9158. $r .= BR.$DSP->input_textarea('tb_content', $content, '20', 'textarea', '100%');
  9159. // Submit button
  9160. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  9161. $r .= $DSP->form_close();
  9162. $DSP->title = $LANG->line('edit_trackback');
  9163. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_trackbacks'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id, $LANG->line('comments')).$DSP->crumb_item($LANG->line('edit_trackback'));
  9164. $DSP->body = $r;
  9165. }
  9166. /* END */
  9167. /** -----------------------------------------
  9168. /** Update comment
  9169. /** -----------------------------------------*/
  9170. function update_comment()
  9171. {
  9172. global $IN, $DSP, $DB, $LANG, $REGX, $SESS, $FNS, $EXT;
  9173. $comment_id = $IN->GBL('comment_id');
  9174. $author_id = $IN->GBL('author_id');
  9175. $weblog_id = $IN->GBL('weblog_id');
  9176. $entry_id = $IN->GBL('entry_id');
  9177. if ($comment_id == FALSE OR ! is_numeric($comment_id) OR ! is_numeric($weblog_id) OR ! is_numeric($entry_id))
  9178. {
  9179. return $DSP->no_access_message();
  9180. }
  9181. if ($author_id === FALSE)
  9182. {
  9183. return $DSP->no_access_message();
  9184. }
  9185. if ($IN->GBL('validate') == 1)
  9186. {
  9187. if ( ! $DSP->allowed_group('can_moderate_comments'))
  9188. {
  9189. return $DSP->no_access_message();
  9190. }
  9191. $sql = "SELECT COUNT(*) AS count
  9192. FROM exp_comments, exp_weblogs
  9193. WHERE comment_id = '$comment_id' ";
  9194. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  9195. $query = $DB->query($sql);
  9196. if ($query->row['count'] == 0)
  9197. {
  9198. return $DSP->no_access_message();
  9199. }
  9200. }
  9201. else
  9202. {
  9203. if ( ! $DSP->allowed_group('can_edit_all_comments'))
  9204. {
  9205. if ( ! $DSP->allowed_group('can_edit_own_comments'))
  9206. {
  9207. return $DSP->no_access_message();
  9208. }
  9209. else
  9210. {
  9211. $sql = "SELECT exp_weblog_titles.author_id
  9212. FROM exp_weblog_titles, exp_comments
  9213. WHERE exp_weblog_titles.entry_id = exp_comments.entry_id
  9214. AND exp_comments.comment_id = '$comment_id'";
  9215. $query = $DB->query($sql);
  9216. if ($query->row['author_id'] != $SESS->userdata('member_id'))
  9217. {
  9218. return $DSP->no_access_message();
  9219. }
  9220. }
  9221. }
  9222. }
  9223. /** ---------------------------------------
  9224. /** Fetch comment display preferences
  9225. /** ---------------------------------------*/
  9226. $query = $DB->query("SELECT exp_weblogs.comment_require_email
  9227. FROM exp_weblogs, exp_comments
  9228. WHERE exp_comments.weblog_id = exp_weblogs.weblog_id
  9229. AND exp_comments.comment_id = '$comment_id'");
  9230. if ($query->num_rows == 0)
  9231. {
  9232. return $DSP->error_message($LANG->line('no_weblog_exits'));
  9233. }
  9234. foreach ($query->row as $key => $val)
  9235. {
  9236. $$key = $val;
  9237. }
  9238. /** -------------------------------------
  9239. /** Error checks
  9240. /** -------------------------------------*/
  9241. $error = array();
  9242. if ($author_id == 0)
  9243. {
  9244. // Fetch language file
  9245. $LANG->fetch_language_file('myaccount');
  9246. if ($comment_require_email == 'y')
  9247. {
  9248. /** -------------------------------------
  9249. /** Is email missing?
  9250. /** -------------------------------------*/
  9251. if ($_POST['email'] == '')
  9252. {
  9253. $error[] = $LANG->line('missing_email');
  9254. }
  9255. /** -------------------------------------
  9256. /** Is email valid?
  9257. /** -------------------------------------*/
  9258. if ( ! $REGX->valid_email($_POST['email']))
  9259. {
  9260. $error[] = $LANG->line('invalid_email_address');
  9261. }
  9262. /** -------------------------------------
  9263. /** Is email banned?
  9264. /** -------------------------------------*/
  9265. if ($SESS->ban_check('email', $_POST['email']))
  9266. {
  9267. $error[] = $LANG->line('banned_email');
  9268. }
  9269. }
  9270. }
  9271. /** -------------------------------------
  9272. /** Is comment missing?
  9273. /** -------------------------------------*/
  9274. if ($_POST['comment'] == '')
  9275. {
  9276. $error[] = $LANG->line('missing_comment');
  9277. }
  9278. /** -------------------------------------
  9279. /** Display error is there are any
  9280. /** -------------------------------------*/
  9281. if (count($error) > 0)
  9282. {
  9283. $msg = '';
  9284. foreach($error as $val)
  9285. {
  9286. $msg .= $val.'<br />';
  9287. }
  9288. return $DSP->error_message($msg);
  9289. }
  9290. // Build query
  9291. if ($author_id == 0)
  9292. {
  9293. $data = array(
  9294. 'name' => $_POST['name'],
  9295. 'email' => $_POST['email'],
  9296. 'url' => $_POST['url'],
  9297. 'location' => $_POST['location'],
  9298. 'comment' => $_POST['comment']
  9299. );
  9300. }
  9301. else
  9302. {
  9303. $data = array(
  9304. 'comment' => $_POST['comment']
  9305. );
  9306. }
  9307. $DB->query($DB->update_string('exp_comments', $data, "comment_id = '$comment_id'"));
  9308. // -------------------------------------------
  9309. // 'update_comment_additional' hook.
  9310. // - Add additional processing on comment update.
  9311. //
  9312. $edata = $EXT->call_extension('update_comment_additional', $comment_id, $data);
  9313. if ($EXT->end_script === TRUE) return;
  9314. //
  9315. // -------------------------------------------
  9316. $FNS->clear_caching('all');
  9317. $current_page = ( ! isset($_POST['current_page'])) ? 0 : $_POST['current_page'];
  9318. if ($IN->GBL('keywords') !== FALSE)
  9319. {
  9320. $url = BASE.AMP.'C=edit'.
  9321. AMP.'M=view_entries'.
  9322. AMP.'search_in=comments'.
  9323. AMP.'rownum='.$current_page.
  9324. AMP.'order=desc'.
  9325. AMP.'keywords='.$IN->GBL('keywords');
  9326. }
  9327. elseif ($IN->GBL('validate', 'POST') == 1)
  9328. {
  9329. $url = BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'validate=1';
  9330. }
  9331. else
  9332. {
  9333. $url = BASE.AMP.'C=edit'.
  9334. AMP.'M=view_comments'.
  9335. AMP.'weblog_id='.$weblog_id.
  9336. AMP.'entry_id='.$entry_id.
  9337. AMP.'current_page='.$current_page;
  9338. }
  9339. $FNS->redirect($url);
  9340. exit;
  9341. }
  9342. /* END */
  9343. /** -----------------------------------------
  9344. /** Update trackback
  9345. /** -----------------------------------------*/
  9346. function update_trackback()
  9347. {
  9348. global $IN, $DSP, $DB, $LANG, $REGX, $SESS, $FNS, $EXT;
  9349. $trackback_id = $IN->GBL('trackback_id');
  9350. $weblog_id = $IN->GBL('weblog_id');
  9351. $entry_id = $IN->GBL('entry_id');
  9352. if ($trackback_id == FALSE OR ! is_numeric($trackback_id) OR ! is_numeric($weblog_id) OR ! is_numeric($entry_id))
  9353. {
  9354. return $DSP->no_access_message();
  9355. }
  9356. if ( ! $DSP->allowed_group('can_edit_all_comments'))
  9357. {
  9358. if ( ! $DSP->allowed_group('can_edit_own_comments'))
  9359. {
  9360. return $DSP->no_access_message();
  9361. }
  9362. else
  9363. {
  9364. $sql = "SELECT exp_weblog_titles.author_id
  9365. FROM exp_weblog_titles, exp_trackbacks
  9366. WHERE exp_weblog_titles.entry_id = exp_trackbacks.entry_id
  9367. AND exp_trackbacks.trackback_id = '$trackback_id'";
  9368. $query = $DB->query($sql);
  9369. if ($query->row['author_id'] != $SESS->userdata('member_id'))
  9370. {
  9371. return $DSP->no_access_message();
  9372. }
  9373. }
  9374. }
  9375. /** -------------------------------------
  9376. /** Error checks
  9377. /** -------------------------------------*/
  9378. $error = array();
  9379. /** -------------------------------------
  9380. /** Is content missing?
  9381. /** -------------------------------------*/
  9382. foreach(array('url', 'weblog', 'title', 'tb_content') as $value)
  9383. if (!isset($_POST[$value]) OR $_POST[$value] == '')
  9384. {
  9385. $error[] = $LANG->line('field_blank');
  9386. }
  9387. /** -------------------------------------
  9388. /** Display error is there are any
  9389. /** -------------------------------------*/
  9390. if (count($error) > 0)
  9391. {
  9392. $msg = '';
  9393. $error = array_unique($error);
  9394. foreach($error as $val)
  9395. {
  9396. $msg .= $val.'<br />';
  9397. }
  9398. return $DSP->error_message($msg);
  9399. }
  9400. // Build query
  9401. $data = array( 'title' => $_POST['title'],
  9402. 'weblog_name' => $_POST['weblog'],
  9403. 'trackback_url' => $_POST['url'],
  9404. 'content' => $_POST['tb_content']);
  9405. $DB->query($DB->update_string('exp_trackbacks', $data, "trackback_id = '$trackback_id'"));
  9406. // -------------------------------------------
  9407. // 'update_trackback_additional' hook.
  9408. // - Add additional processing on trackback update.
  9409. //
  9410. $edata = $EXT->call_extension('update_trackback_additional', $trackback_id, $data);
  9411. if ($EXT->end_script === TRUE) return;
  9412. //
  9413. // -------------------------------------------
  9414. $FNS->clear_caching('all');
  9415. $current_page = ( ! isset($_POST['current_page'])) ? 0 : $_POST['current_page'];
  9416. $url = BASE.AMP.'C=edit'.AMP.'M=view_trackbacks'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id.AMP.'current_page='.$current_page;
  9417. $FNS->redirect($url);
  9418. exit;
  9419. }
  9420. /* END */
  9421. /** -----------------------------------------
  9422. /** Modify Comments
  9423. /** -----------------------------------------*/
  9424. function modify_comments()
  9425. {
  9426. global $IN;
  9427. switch($IN->GBL('action', 'POST'))
  9428. {
  9429. case 'open':
  9430. $this->change_comment_status('open');
  9431. break;
  9432. case 'close':
  9433. $this->change_comment_status('close');
  9434. break;
  9435. case 'move':
  9436. $this->move_comments_form();
  9437. break;
  9438. default:
  9439. $this->delete_comment_confirm();
  9440. break;
  9441. }
  9442. }
  9443. /* END */
  9444. /** -----------------------------------------
  9445. /** Delete comment/trackback confirmation
  9446. /** -----------------------------------------*/
  9447. function delete_comment_confirm()
  9448. {
  9449. global $IN, $DSP, $DB, $LANG, $SESS;
  9450. $weblog_id = $IN->GBL('weblog_id');
  9451. $entry_id = $IN->GBL('entry_id');
  9452. if ( ! $IN->GBL('toggle', 'POST') && ! $IN->GBL('comment_id') && ! $IN->GBL('trackback_id'))
  9453. {
  9454. return $this->edit_entries();
  9455. }
  9456. $comments = array();
  9457. $trackbacks = array();
  9458. foreach ($_POST as $key => $val)
  9459. {
  9460. if (strstr($key, 'toggle') AND ! is_array($val))
  9461. {
  9462. if (substr($val, 0, 1) == 't')
  9463. {
  9464. $trackbacks[] = $DB->escape_str(substr($val, 1));
  9465. }
  9466. elseif (substr($val, 0, 1) == 'c')
  9467. {
  9468. $comments[] = $DB->escape_str(substr($val, 1));
  9469. }
  9470. }
  9471. }
  9472. if($IN->GBL('comment_id') !== FALSE && is_numeric($IN->GBL('comment_id')))
  9473. {
  9474. $comments[] = $DB->escape_str($IN->GBL('comment_id'));
  9475. }
  9476. elseif($IN->GBL('trackback_id') !== FALSE && is_numeric($IN->GBL('trackback_id')))
  9477. {
  9478. $trackbacks[] = $DB->escape_str($IN->GBL('trackback_id'));
  9479. }
  9480. if ($IN->GBL('validate') == 1)
  9481. {
  9482. if (sizeof($comments) == 0)
  9483. {
  9484. return $DSP->no_access_message();
  9485. }
  9486. if ( ! $DSP->allowed_group('can_moderate_comments'))
  9487. {
  9488. return $DSP->no_access_message();
  9489. }
  9490. $sql = "SELECT COUNT(*) AS count
  9491. FROM exp_comments, exp_weblogs
  9492. WHERE comment_id IN ('".implode("','", $comments)."') ";
  9493. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  9494. $query = $DB->query($sql);
  9495. if ($query->row['count'] == 0)
  9496. {
  9497. return $DSP->no_access_message();
  9498. }
  9499. }
  9500. else
  9501. {
  9502. if ( ! $DSP->allowed_group('can_delete_all_comments'))
  9503. {
  9504. if ( ! $DSP->allowed_group('can_delete_own_comments'))
  9505. {
  9506. return $DSP->no_access_message();
  9507. }
  9508. else
  9509. {
  9510. if (sizeof($comments) > 0)
  9511. {
  9512. $sql = "SELECT exp_weblog_titles.author_id, exp_comments.comment_id
  9513. FROM exp_weblog_titles, exp_comments
  9514. WHERE exp_weblog_titles.entry_id = exp_comments.entry_id
  9515. AND exp_comments.comment_id IN ('".implode("','", $comments)."')";
  9516. }
  9517. elseif (sizeof($trackbacks) > 0)
  9518. {
  9519. $sql = "SELECT exp_weblog_titles.author_id, exp_trackbacks.trackback_id
  9520. FROM exp_weblog_titles, exp_trackbacks
  9521. WHERE exp_weblog_titles.entry_id = exp_trackbacks.entry_id
  9522. AND exp_trackbacks.trackback_id IN ('".implode("','", $trackbacks)."')";
  9523. }
  9524. $trackbacks = array();
  9525. $comments = array();
  9526. $query = $DB->query($sql);
  9527. if ($query->num_rows > 0)
  9528. {
  9529. foreach($query->result as $row)
  9530. {
  9531. if ($row['author_id'] == $SESS->userdata('member_id'))
  9532. {
  9533. if (isset($row['trackback_id']))
  9534. {
  9535. $trackbacks[] = $row['trackback_id'];
  9536. }
  9537. else
  9538. {
  9539. $comments[] = $row['comment_id'];
  9540. }
  9541. }
  9542. }
  9543. }
  9544. }
  9545. }
  9546. }
  9547. if (sizeof($trackbacks) == 0 && sizeof($comments) == 0)
  9548. {
  9549. return $this->edit_entries();
  9550. }
  9551. $r = $DSP->form_open(array('action' => 'C=edit'.AMP.'M=del_comment'));
  9552. $validate = ($IN->GBL('validate') == 1) ? 1 : 0;
  9553. $r .= $DSP->input_hidden('validate', $validate);
  9554. $r .= $DSP->input_hidden('comment_ids', implode('|', $comments));
  9555. $r .= $DSP->input_hidden('trackback_ids', implode('|', $trackbacks));
  9556. if ($IN->GBL('keywords') !== FALSE)
  9557. {
  9558. $r .= $DSP->input_hidden('keywords', $IN->GBL('keywords'));
  9559. $r .= $DSP->input_hidden('current_page', $IN->GBL('current_page'));
  9560. }
  9561. $r .= $DSP->qdiv('alertHeading', $LANG->line('delete_confirm'));
  9562. $r .= $DSP->div('box');
  9563. if (sizeof($comments) > 0)
  9564. {
  9565. if (sizeof($comments) == 1)
  9566. {
  9567. $r .= '<b>'.$LANG->line('delete_comment_confirm').'</b>';
  9568. }
  9569. else
  9570. {
  9571. $r .= '<b>'.$LANG->line('delete_comments_confirm').'</b>';
  9572. }
  9573. }
  9574. else
  9575. {
  9576. if (sizeof($trackbacks) == 1)
  9577. {
  9578. $r .= '<b>'.$LANG->line('delete_trackback_confirm').'</b>';
  9579. }
  9580. else
  9581. {
  9582. $r .= '<b>'.$LANG->line('delete_trackbacks_confirm').'</b>';
  9583. }
  9584. }
  9585. $r .= $DSP->br(2).
  9586. $DSP->qdiv('alert', $LANG->line('action_can_not_be_undone')).
  9587. $DSP->br().
  9588. $DSP->input_submit($LANG->line('delete')).
  9589. $DSP->div_c().
  9590. $DSP->form_close();
  9591. $DSP->title = $LANG->line('delete_confirm');
  9592. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id, $LANG->line('comments')).$DSP->crumb_item($LANG->line('edit_comment'));
  9593. $DSP->body = $r;
  9594. }
  9595. /* END */
  9596. /** -----------------------------------------
  9597. /** Change Comment Status
  9598. /** -----------------------------------------*/
  9599. function change_comment_status($status='')
  9600. {
  9601. global $IN, $DSP, $DB, $LANG, $PREFS, $REGX, $FNS, $SESS, $STAT;
  9602. $weblog_id = $IN->GBL('weblog_id');
  9603. $entry_id = $IN->GBL('entry_id');
  9604. $current_page = $IN->GBL('current_page');
  9605. $comments = array();
  9606. $trackbacks = array();
  9607. foreach ($_POST as $key => $val)
  9608. {
  9609. if (strstr($key, 'toggle') AND ! is_array($val))
  9610. {
  9611. if (substr($val, 0, 1) == 'c')
  9612. {
  9613. $comments[] = $DB->escape_str(substr($val, 1));
  9614. }
  9615. }
  9616. }
  9617. if($IN->GBL('comment_id') !== FALSE && is_numeric($IN->GBL('comment_id')))
  9618. {
  9619. $comments[] = $DB->escape_str($IN->GBL('comment_id'));
  9620. }
  9621. if (sizeof($comments) == 0)
  9622. {
  9623. return $DSP->no_access_message();
  9624. }
  9625. if ( ! $DSP->allowed_group('can_moderate_comments') && ! $DSP->allowed_group('can_edit_all_comments'))
  9626. {
  9627. return $DSP->no_access_message();
  9628. }
  9629. if ($DSP->allowed_group('can_edit_all_comments'))
  9630. {
  9631. // Can Edit All Comments
  9632. $sql = "SELECT exp_comments.entry_id, exp_comments.weblog_id, exp_comments.author_id
  9633. FROM exp_comments
  9634. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')";
  9635. }
  9636. else
  9637. {
  9638. // Can Moderate Comments, but only from non-USER blogs.
  9639. $sql = "SELECT exp_comments.entry_id, exp_comments.weblog_id, exp_comments.author_id
  9640. FROM exp_comments, exp_weblogs
  9641. WHERE exp_comments.comment_id IN ('".implode("','", $comments)."')
  9642. AND exp_comments.weblog_id = exp_weblogs.weblog_id ";
  9643. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  9644. }
  9645. /** -------------------------------
  9646. /** Retrieve Our Results
  9647. /** -------------------------------*/
  9648. $query = $DB->query($sql);
  9649. if ($query->num_rows == 0)
  9650. {
  9651. return $DSP->no_access_message();
  9652. }
  9653. $entry_ids = array();
  9654. $author_ids = array();
  9655. $weblog_ids = array();
  9656. foreach($query->result as $row)
  9657. {
  9658. $entry_ids[] = $row['entry_id'];
  9659. $author_ids[] = $row['author_id'];
  9660. $weblog_ids[] = $row['weblog_id'];
  9661. }
  9662. $entry_ids = array_unique($entry_ids);
  9663. $author_ids = array_unique($author_ids);
  9664. $weblog_ids = array_unique($weblog_ids);
  9665. /** -------------------------------
  9666. /** Change Status
  9667. /** -------------------------------*/
  9668. $status = ($status == 'close' OR (isset($_GET['status']) AND $_GET['status'] == 'close')) ? 'c' : 'o';
  9669. $DB->query("UPDATE exp_comments SET status = '$status' WHERE comment_id IN ('".implode("','", $comments)."') ");
  9670. foreach(array_unique($entry_ids) as $entry_id)
  9671. {
  9672. $query = $DB->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$DB->escape_str($entry_id)."'");
  9673. $comment_date = ($query->num_rows == 0 OR !is_numeric($query->row['max_date'])) ? 0 : $query->row['max_date'];
  9674. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o'");
  9675. $DB->query("UPDATE exp_weblog_titles SET comment_total = '".($query->row['count'])."', recent_comment_date = '$comment_date' WHERE entry_id = '".$DB->escape_str($entry_id)."'");
  9676. }
  9677. // Quicker and updates just the weblogs
  9678. foreach(array_unique($weblog_ids) as $weblog_id) { $STAT->update_comment_stats($weblog_id, '', FALSE); }
  9679. // Updates the total stats
  9680. $STAT->update_comment_stats();
  9681. foreach(array_unique($author_ids) as $author_id)
  9682. {
  9683. $res = $DB->query("SELECT COUNT(comment_id) AS comment_total, MAX(comment_date) AS comment_date FROM exp_comments WHERE author_id = '$author_id'");
  9684. $comment_total = $res->row['comment_total'];
  9685. $comment_date = (!empty($res->row['comment_date'])) ? $res->row['comment_date'] : 0;
  9686. $DB->query($DB->update_string('exp_members', array('total_comments' => $comment_total, 'last_comment_date' => $comment_date), "member_id = '$author_id'"));
  9687. }
  9688. /** ----------------------------------------
  9689. /** Send email notification
  9690. /** ----------------------------------------*/
  9691. if ($status == 'o')
  9692. {
  9693. /** ----------------------------------------
  9694. /** Instantiate Typography class
  9695. /** ----------------------------------------*/
  9696. if ( ! class_exists('Typography'))
  9697. {
  9698. require PATH_CORE.'core.typography'.EXT;
  9699. }
  9700. $TYPE = new Typography(0);
  9701. /** ----------------------------------------
  9702. /** Go Through Array of Entries
  9703. /** ----------------------------------------*/
  9704. foreach ($comments as $comment_id)
  9705. {
  9706. $query = $DB->query("SELECT comment, name, email, comment_date, entry_id
  9707. FROM exp_comments
  9708. WHERE comment_id = '".$DB->escape_str($comment_id)."'");
  9709. /*
  9710. Find all of the unique commenters for this entry that have
  9711. notification turned on, posted at/before this comment
  9712. and do not have the same email address as this comment.
  9713. */
  9714. $results = $DB->query("SELECT DISTINCT(email), name, comment_id
  9715. FROM exp_comments
  9716. WHERE status = 'o'
  9717. AND entry_id = '".$DB->escape_str($query->row['entry_id'])."'
  9718. AND notify = 'y'
  9719. AND email != '".$DB->escape_str($query->row['email'])."'
  9720. AND comment_date <= '".$DB->escape_str($query->row['comment_date'])."'");
  9721. $recipients = array();
  9722. if ($results->num_rows > 0)
  9723. {
  9724. foreach ($results->result as $row)
  9725. {
  9726. $recipients[] = array($row['email'], $row['comment_id'], $row['name']);
  9727. }
  9728. }
  9729. $email_msg = '';
  9730. if (count($recipients) > 0)
  9731. {
  9732. $comment = $TYPE->parse_type( $query->row['comment'],
  9733. array(
  9734. 'text_format' => 'none',
  9735. 'html_format' => 'none',
  9736. 'auto_links' => 'n',
  9737. 'allow_img_url' => 'n'
  9738. )
  9739. );
  9740. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  9741. $action_id = $FNS->fetch_action_id('Comment_CP', 'delete_comment_notification');
  9742. $results = $DB->query("SELECT wt.title, wt.url_title, w.blog_title, w.comment_url, w.blog_url
  9743. FROM exp_weblog_titles wt, exp_weblogs w
  9744. WHERE wt.entry_id = '".$DB->escape_str($query->row['entry_id'])."'
  9745. AND wt.weblog_id = w.weblog_id");
  9746. $com_url = ($results->row['comment_url'] == '') ? $results->row['blog_url'] : $results->row['comment_url'];
  9747. $swap = array(
  9748. 'name_of_commenter' => $query->row['name'],
  9749. 'name' => $query->row['name'],
  9750. 'weblog_name' => $results->row['blog_title'],
  9751. 'entry_title' => $results->row['title'],
  9752. 'site_name' => stripslashes($PREFS->ini('site_name')),
  9753. 'site_url' => $PREFS->ini('site_url'),
  9754. 'comment' => $comment,
  9755. 'comment_id' => $comment_id,
  9756. 'comment_url' => $FNS->remove_double_slashes($com_url.'/'.$results->row['url_title'].'/')
  9757. );
  9758. $template = $FNS->fetch_email_template('comment_notification');
  9759. $email_tit = $FNS->var_swap($template['title'], $swap);
  9760. $email_msg = $FNS->var_swap($template['data'], $swap);
  9761. /** ----------------------------
  9762. /** Send email
  9763. /** ----------------------------*/
  9764. if ( ! class_exists('EEmail'))
  9765. {
  9766. require PATH_CORE.'core.email'.EXT;
  9767. }
  9768. $email = new EEmail;
  9769. $email->wordwrap = true;
  9770. $sent = array();
  9771. foreach ($recipients as $val)
  9772. {
  9773. if ( ! in_array($val['0'], $sent))
  9774. {
  9775. $title = $email_tit;
  9776. $message = $email_msg;
  9777. // Deprecate the {name} variable at some point
  9778. $title = str_replace('{name}', $val['2'], $title);
  9779. $message = str_replace('{name}', $val['2'], $message);
  9780. $title = str_replace('{name_of_recipient}', $val['2'], $title);
  9781. $message = str_replace('{name_of_recipient}', $val['2'], $message);
  9782. $title = str_replace('{notification_removal_url}', $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$val['1'], $title);
  9783. $message = str_replace('{notification_removal_url}', $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$val['1'], $message);
  9784. $email->initialize();
  9785. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  9786. $email->to($val['0']);
  9787. $email->subject($title);
  9788. $email->message($REGX->entities_to_ascii($message));
  9789. $email->Send();
  9790. $sent[] = $val['0'];
  9791. }
  9792. }
  9793. }
  9794. }
  9795. }
  9796. $FNS->clear_caching('all');
  9797. $val = ($IN->GBL('validate') == 1) ? AMP.'validate=1' : '';
  9798. if ($IN->GBL('search_in') !== FALSE)
  9799. {
  9800. $url = BASE.AMP.'C=edit'.
  9801. AMP.'M=view_entries'.
  9802. AMP.'search_in=comments'.
  9803. AMP.'rownum='.$IN->GBL('current_page').
  9804. AMP.'order=desc'.
  9805. AMP.'keywords='.$IN->GBL('keywords');
  9806. }
  9807. else
  9808. {
  9809. $url = BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'weblog_id='.$weblog_id.AMP.'entry_id='.$entry_id.AMP.'current_page='.$current_page.AMP.'U=1'.$val;
  9810. }
  9811. $FNS->redirect($url);
  9812. exit;
  9813. }
  9814. /* END */
  9815. /** -----------------------------------------
  9816. /** Delete comment/trackback
  9817. /** -----------------------------------------*/
  9818. function delete_comment()
  9819. {
  9820. global $IN, $DSP, $DB, $LANG, $SESS, $FNS, $STAT, $EXT;
  9821. $comment_id = $IN->GBL('comment_ids');
  9822. $trackback_id = $IN->GBL('trackback_ids');
  9823. if ($trackback_id == FALSE AND $comment_id == FALSE)
  9824. {
  9825. return $DSP->no_access_message();
  9826. }
  9827. if ($comment_id != FALSE)
  9828. {
  9829. if ( ! preg_match("/^[0-9]+$/", str_replace('|', '', $comment_id)))
  9830. {
  9831. return $DSP->no_access_message();
  9832. }
  9833. $sql = "SELECT exp_weblog_titles.author_id, exp_weblog_titles.entry_id, exp_weblog_titles.weblog_id, exp_weblog_titles.comment_total
  9834. FROM exp_weblog_titles, exp_comments
  9835. WHERE exp_weblog_titles.entry_id = exp_comments.entry_id
  9836. AND exp_comments.comment_id IN ('".str_replace('|', "','", $DB->escape_str($comment_id))."')";
  9837. }
  9838. else
  9839. {
  9840. if ( ! is_numeric(str_replace('|', '', $trackback_id)))
  9841. {
  9842. return $DSP->no_access_message();
  9843. }
  9844. $sql = "SELECT exp_weblog_titles.author_id, exp_trackbacks.entry_id, exp_weblog_titles.weblog_id, exp_weblog_titles.trackback_total
  9845. FROM exp_weblog_titles, exp_trackbacks
  9846. WHERE exp_weblog_titles.entry_id = exp_trackbacks.entry_id
  9847. AND exp_trackbacks.trackback_id IN ('".str_replace('|', "','", $DB->escape_str($trackback_id))."')";
  9848. }
  9849. $query = $DB->query($sql);
  9850. if ($query->num_rows == 0)
  9851. {
  9852. return $DSP->no_access_message();
  9853. }
  9854. $entry_ids = array();
  9855. $author_ids = array();
  9856. $weblog_ids = array();
  9857. foreach($query->result as $row)
  9858. {
  9859. $entry_ids[] = $row['entry_id'];
  9860. $author_ids[] = $row['author_id'];
  9861. $weblog_ids[] = $row['weblog_id'];
  9862. }
  9863. $entry_ids = array_unique($entry_ids);
  9864. $author_ids = array_unique($author_ids);
  9865. $weblog_ids = array_unique($weblog_ids);
  9866. /** -------------------------------
  9867. /** Validation Checks
  9868. /** -------------------------------*/
  9869. if ($IN->GBL('validate') == 1)
  9870. {
  9871. if ( ! $DSP->allowed_group('can_moderate_comments'))
  9872. {
  9873. return $DSP->no_access_message();
  9874. }
  9875. $sql = "SELECT COUNT(*) AS count
  9876. FROM exp_comments, exp_weblogs
  9877. WHERE comment_id IN ('".str_replace('|', "','", $DB->escape_str($comment_id))."') ";
  9878. $sql .= (USER_BLOG !== FALSE) ? "AND exp_weblogs.weblog_id = '".UB_BLOG_ID."' " : "AND exp_weblogs.is_user_blog = 'n' ";
  9879. $query = $DB->query($sql);
  9880. if ($query->row['count'] == 0)
  9881. {
  9882. return $DSP->no_access_message();
  9883. }
  9884. }
  9885. else
  9886. {
  9887. if ( ! $DSP->allowed_group('can_delete_all_comments'))
  9888. {
  9889. if ( ! $DSP->allowed_group('can_delete_own_comments'))
  9890. {
  9891. return $DSP->no_access_message();
  9892. }
  9893. else
  9894. {
  9895. foreach($query->result as $row)
  9896. {
  9897. if ($row['author_id'] != $SESS->userdata('member_id'))
  9898. {
  9899. return $DSP->no_access_message();
  9900. }
  9901. }
  9902. }
  9903. }
  9904. }
  9905. /** --------------------------------
  9906. /** Update Entry and Weblog Stats
  9907. /** --------------------------------*/
  9908. if ($comment_id != FALSE)
  9909. {
  9910. $DB->query("DELETE FROM exp_comments WHERE comment_id IN ('".str_replace('|', "','", $DB->escape_str($comment_id))."')");
  9911. foreach($entry_ids as $entry_id)
  9912. {
  9913. $query = $DB->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$DB->escape_str($entry_id)."'");
  9914. $comment_date = ($query->num_rows == 0 OR !is_numeric($query->row['max_date'])) ? 0 : $query->row['max_date'];
  9915. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o'");
  9916. $DB->query("UPDATE exp_weblog_titles SET comment_total = '".($query->row['count'])."', recent_comment_date = '$comment_date' WHERE entry_id = '".$DB->escape_str($entry_id)."'");
  9917. }
  9918. // Quicker and updates just the weblogs
  9919. foreach($weblog_ids as $weblog_id) { $STAT->update_comment_stats($weblog_id, '', FALSE); }
  9920. // Updates the total stats
  9921. $STAT->update_comment_stats();
  9922. foreach($author_ids as $author_id)
  9923. {
  9924. $res = $DB->query("SELECT COUNT(comment_id) AS comment_total, MAX(comment_date) AS comment_date FROM exp_comments WHERE author_id = '$author_id'");
  9925. $comment_total = $res->row['comment_total'];
  9926. $comment_date = (!empty($res->row['comment_date'])) ? $res->row['comment_date'] : 0;
  9927. $DB->query($DB->update_string('exp_members', array('total_comments' => $comment_total, 'last_comment_date' => $comment_date), "member_id = '$author_id'"));
  9928. }
  9929. $msg = $LANG->line('comment_deleted');
  9930. }
  9931. else
  9932. {
  9933. $DB->query("DELETE FROM exp_trackbacks WHERE trackback_id IN ('".str_replace('|', "','", $DB->escape_str($trackback_id))."')");
  9934. foreach($entry_ids as $entry_id)
  9935. {
  9936. $query = $DB->query("SELECT MAX(trackback_date) AS max_date FROM exp_trackbacks WHERE entry_id = '".$DB->escape_str($entry_id)."'");
  9937. $trackback_date = ($query->num_rows == 0 OR !is_numeric($query->row['max_date'])) ? 0 : $query->row['max_date'];
  9938. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_trackbacks WHERE entry_id = '".$DB->escape_str($entry_id)."'");
  9939. $DB->query("UPDATE exp_weblog_titles SET trackback_total = '".($query->row['count'])."', recent_trackback_date = '$trackback_date' WHERE entry_id = '$entry_id'");
  9940. }
  9941. foreach($weblog_ids as $weblog_id) { $STAT->update_trackback_stats($weblog_id); }
  9942. $msg = $LANG->line('trackback_deleted');
  9943. }
  9944. // -------------------------------------------
  9945. // 'delete_comment_additional' hook.
  9946. // - Add additional processing on comment delete
  9947. //
  9948. $edata = $EXT->call_extension('delete_comment_additional');
  9949. if ($EXT->end_script === TRUE) return;
  9950. //
  9951. // -------------------------------------------
  9952. $FNS->clear_caching('all');
  9953. if ($IN->GBL('validate', 'POST') == 1)
  9954. {
  9955. $FNS->redirect(BASE.AMP.'C=edit'.AMP.'M=view_comments'.AMP.'validate=1');
  9956. exit;
  9957. }
  9958. $message = $DSP->qdiv('success', $msg);
  9959. if ($IN->GBL('keywords') !== FALSE)
  9960. {
  9961. $url = BASE.AMP.'C=edit'.
  9962. AMP.'M=view_entries'.
  9963. AMP.'search_in='.(($comment_id != FALSE) ? 'comments' : 'trackbacks').
  9964. AMP.'rownum='.$IN->GBL('current_page').
  9965. AMP.'order=desc'.
  9966. AMP.'keywords='.$IN->GBL('keywords');
  9967. $FNS->redirect($url);
  9968. exit;
  9969. }
  9970. elseif ($comment_id != FALSE)
  9971. {
  9972. $this->view_comments($weblog_id, $entry_id, $message);
  9973. }
  9974. else
  9975. {
  9976. $this->view_trackbacks($weblog_id, $entry_id, $message);
  9977. }
  9978. }
  9979. /* END */
  9980. /** -----------------------------------------
  9981. /** Base IFRAME for Spell Check
  9982. /** -----------------------------------------*/
  9983. function spellcheck_iframe()
  9984. {
  9985. global $DSP;
  9986. if ( ! class_exists('Spellcheck'))
  9987. {
  9988. require PATH_CORE.'core.spellcheck'.EXT;
  9989. }
  9990. return Spellcheck::iframe($DSP->fetch_stylesheet());
  9991. }
  9992. /* END */
  9993. /** -----------------------------------------
  9994. /** Spell Check for Textareas
  9995. /** -----------------------------------------*/
  9996. function spellcheck()
  9997. {
  9998. if ( ! class_exists('Spellcheck'))
  9999. {
  10000. require PATH_CORE.'core.spellcheck'.EXT;
  10001. }
  10002. return Spellcheck::check();
  10003. }
  10004. /* END */
  10005. /** -----------------------------------------
  10006. /** Emoticons window - used with the stand-alone entry form
  10007. /** -----------------------------------------*/
  10008. function emoticons()
  10009. {
  10010. global $IN, $DSP, $LANG, $PREFS, $DB;
  10011. if ( ! $field_group = $IN->GBL('field_group', 'GET'))
  10012. {
  10013. return;
  10014. }
  10015. if ( ! is_file(PATH_MOD.'emoticon/emoticons'.EXT))
  10016. {
  10017. return $DSP->error_message($LANG->line('no_emoticons'));
  10018. }
  10019. else
  10020. {
  10021. require PATH_MOD.'emoticon/emoticons'.EXT;
  10022. }
  10023. if ( ! is_array($smileys))
  10024. {
  10025. return;
  10026. }
  10027. $path = $PREFS->ini('emoticon_path', 1);
  10028. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE group_id = '".$field_group."' AND field_type != 'rel' AND field_type != 'date' AND field_type != 'select' ORDER BY field_order");
  10029. if ($query->num_rows == 0)
  10030. {
  10031. return $DSP->error_message($LANG->line('no_entry_fields'));
  10032. }
  10033. ob_start();
  10034. ?>
  10035. <script type="text/javascript">
  10036. <!--
  10037. function add_smiley(smiley)
  10038. {
  10039. var form = document.forms[0];
  10040. <?php
  10041. $n = 0;
  10042. foreach ($query->result as $row)
  10043. {
  10044. $js_element = ($query->num_rows > 1) ? "[{$n}]" : '';
  10045. ?>
  10046. if (form.which<?php echo $js_element; ?>.checked)
  10047. {
  10048. opener.document.getElementById('entryform').field_id_<?php echo $row['field_id']; ?>.value += " " + smiley + " ";
  10049. window.close();
  10050. opener.window.document.getElementById('entryform').field_id_<?php echo $row['field_id']; ?>.focus();
  10051. }
  10052. <?php
  10053. $n++;
  10054. }
  10055. ?>
  10056. }
  10057. //-->
  10058. </script>
  10059. <?php
  10060. $javascript = ob_get_contents();
  10061. ob_end_clean();
  10062. $r = $javascript;
  10063. $r .= $DSP->heading($LANG->line('emoticons'));
  10064. $r .= $DSP->qdiv('', BR.$LANG->line('choose_a_destination_for_emoticon').BR.BR);
  10065. $r .= "<form name='upload' method='post' action='' >";
  10066. $i = 1;
  10067. foreach ($query->result as $row)
  10068. {
  10069. $selected = ($i == 1) ? 1 : 0;
  10070. $r .= $DSP->qdiv('', $DSP->input_radio('which', 'field_id_'.$row['field_id'], $selected).NBS.$row['field_label']);
  10071. $i++;
  10072. }
  10073. $r .= $DSP->qdiv('', BR.$LANG->line('click_emoticon').BR.BR);
  10074. $r .= $DSP->table('', '0', '10', '100%');
  10075. $i = 1;
  10076. $dups = array();
  10077. foreach ($smileys as $key => $val)
  10078. {
  10079. if ($i == 1)
  10080. {
  10081. $r .= "<tr>\n";
  10082. }
  10083. if (in_array($smileys[$key]['0'], $dups))
  10084. continue;
  10085. $r .= "<td><a href=\"#\" onclick=\"return add_smiley('".$key."');\"><img src=\"".$path.$smileys[$key]['0']."\" width=\"".$smileys[$key]['1']."\" height=\"".$smileys[$key]['2']."\" alt=\"".$smileys[$key]['3']."\" border=\"0\" /></a></td>\n";
  10086. $dups[] = $smileys[$key]['0'];
  10087. if ($i == 8)
  10088. {
  10089. $r .= "</tr>\n";
  10090. $i = 1;
  10091. }
  10092. else
  10093. {
  10094. $i++;
  10095. }
  10096. }
  10097. $r = rtrim($r);
  10098. if (substr($r, -5) != "</tr>")
  10099. {
  10100. $r .= "</tr>\n";
  10101. }
  10102. $r .= $DSP->table_c();
  10103. $r .= "</form>";
  10104. $DSP->body = $r;
  10105. $DSP->title = $LANG->line('file_upload');
  10106. }
  10107. /* END */
  10108. }
  10109. // END CLASS
  10110. ?>