PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/campsite/src/plugins/blog/classes/Blog.php

https://github.com/joechrysler/Campsite
PHP | 1079 lines | 796 code | 137 blank | 146 comment | 103 complexity | a9d0f6fc3e98c34041233fd6aabfbcfb MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @package Campsite
  4. *
  5. * @author Sebastian Goebel <sebastian.goebel@web.de>
  6. * @copyright 2008 MDLF, Inc.
  7. * @license http://www.gnu.org/licenses/gpl.txt
  8. * @version $Revision$
  9. * @link http://www.sourcefabric.org
  10. */
  11. class Blog extends DatabaseObject {
  12. /**
  13. * The column names used for the primary key.
  14. * @var array
  15. */
  16. var $m_keyColumnNames = array('blog_id');
  17. var $m_keyIsAutoIncrement = true;
  18. var $m_dbTableName = 'plugin_blog_blog';
  19. static $s_dbTableName = 'plugin_blog_blog';
  20. var $m_columnNames = array(
  21. 'blog_id',
  22. 'fk_language_id',
  23. 'fk_user_id',
  24. 'title',
  25. 'date',
  26. 'info',
  27. 'status',
  28. 'admin_status',
  29. 'admin_remark',
  30. 'request_text',
  31. 'entries_online',
  32. 'entries_offline',
  33. 'comments_online',
  34. 'comments_offline',
  35. 'feature',
  36. 'last_modified'
  37. );
  38. static $m_html_allowed_fields = array('info');
  39. /**
  40. * Construct by passing in the primary key to access the article in
  41. * the database.
  42. *
  43. * @param int $p_languageId
  44. * @param int $p_articleNumber
  45. * Not required when creating an article.
  46. */
  47. function Blog($p_blog_id = null)
  48. {
  49. parent::DatabaseObject($this->m_columnNames);
  50. $this->m_data['blog_id'] = $p_blog_id;
  51. if ($this->keyValuesExist()) {
  52. $this->fetch();
  53. $this->m_data['images'] = BlogImageHelper::GetImagePaths('blog', $p_blog_id, true, true);
  54. }
  55. } // constructor
  56. /**
  57. * A way for internal functions to call the superclass create function.
  58. * @param array $p_values
  59. */
  60. function __create($p_values = null) { return parent::create($p_values); }
  61. function create($p_user_id, $p_language_id, $p_title, $p_info, $p_request_text, $p_feature)
  62. {
  63. // Create the record
  64. $values = array(
  65. 'fk_user_id' => $p_user_id,
  66. 'fk_language_id'=> $p_language_id,
  67. 'title' => $p_title,
  68. 'info' => $p_info,
  69. 'request_text' => $p_request_text,
  70. 'feature' => $p_feature,
  71. 'date' => date('Y-m-d H:i:s')
  72. );
  73. $success = parent::create($values);
  74. if (!$success) {
  75. return false;
  76. }
  77. $this->fetch();
  78. $CampCache = CampCache::singleton();
  79. $CampCache->clear('user');
  80. return true;
  81. }
  82. function delete()
  83. {
  84. $blog_id = $this->getProperty('blog_id');
  85. foreach (BlogEntry::getEntries(array('fk_blog_id' => $blog_id)) as $Entry) {
  86. $Entry->delete();
  87. }
  88. parent::delete();
  89. BlogImageHelper::RemoveImageDerivates('entry', $entry_id);
  90. BlogTopic::OnBlogDelete($blog_id);
  91. $CampCache = CampCache::singleton();
  92. $CampCache->clear('user');
  93. }
  94. function getData()
  95. {
  96. return $this->m_data;
  97. }
  98. function getSubject()
  99. {
  100. return $this->getProperty('title');
  101. }
  102. private static function BuildQueryStr($p_cond)
  103. {
  104. if (array_key_exists('fk_user_id', $p_cond)) {
  105. $cond .= " AND fk_user_id = {$p_cond['fk_user_id']}";
  106. }
  107. if (array_key_exists('status', $p_cond)) {
  108. $cond .= " AND status = '{$p_cond['status']}'";
  109. }
  110. if (array_key_exists('admin_status', $p_cond)) {
  111. $cond .= " AND admin_status = '{$p_cond['admin_status']}'";
  112. }
  113. $queryStr = "SELECT blog_id
  114. FROM {self::$s_dbTableName}
  115. WHERE 1 $cond
  116. ORDER BY blog_id DESC";
  117. return $queryStr;
  118. }
  119. function getBlogs($p_cond, $p_currPage=0, $p_perPage=20)
  120. {
  121. global $g_ado_db;
  122. $queryStr = self::BuildQueryStr($p_cond);
  123. $query = $g_ado_db->SelectLimit($queryStr, $p_perPage, ($p_currPage-1) * $p_perPage);
  124. $blogs = array();
  125. while ($row = $query->FetchRow()) {
  126. $tmpBlog = new Blog($row['blog_id']);
  127. $blogs[] = $tmpBlog;
  128. }
  129. return $blogs;
  130. }
  131. function countBlogs($p_cond=array())
  132. {
  133. global $g_ado_db;
  134. $queryStr = self::BuildQueryStr($p_cond);
  135. $query = $g_ado_db->Execute($queryStr); #
  136. return $query->RecordCount();
  137. }
  138. function getBlogEntrys()
  139. {
  140. $BlogEntry = new BlogEntry(array('blog_id' => $this->getProperty('blog_id')));
  141. return $BlogEntry->getEntrys();
  142. }
  143. static function TriggerCounters($p_blog_id)
  144. {
  145. global $g_ado_db;
  146. $blogs_tbl = self::$s_dbTableName;
  147. $entries_tbl = BlogEntry::$s_dbTableName;
  148. $queryStr = "UPDATE $blogs_tbl
  149. SET entries_online =
  150. (SELECT COUNT(entry_id)
  151. FROM $entries_tbl
  152. WHERE fk_blog_id = $p_blog_id AND (status = 'online' AND admin_status = 'online')),
  153. entries_offline =
  154. (SELECT COUNT(entry_id)
  155. FROM $entries_tbl
  156. WHERE fk_blog_id = $p_blog_id AND (status != 'online' OR admin_status != 'online')),
  157. comments_online =
  158. (SELECT SUM(comments_online)
  159. FROM $entries_tbl
  160. WHERE fk_blog_id = $p_blog_id),
  161. comments_offline =
  162. (SELECT SUM(comments_offline)
  163. FROM $entries_tbl
  164. WHERE fk_blog_id = $p_blog_id)
  165. WHERE blog_id = $p_blog_id";
  166. $g_ado_db->Execute($queryStr);
  167. }
  168. private function getFormMask($p_owner=false, $p_admin=false)
  169. {
  170. global $g_user;
  171. $data = $this->getData();
  172. foreach (User::GetUsers() as $User) {
  173. if (1 || $User->hasPermission('PLUGIN_BLOG_USER')) {
  174. $ownerList[$User->getUserId()] = "{$User->getRealName()} ({$User->getUserName()})";
  175. }
  176. }
  177. asort($ownerList);
  178. $languageList = array('' => getGS("---Select language---"));
  179. foreach (Language::GetLanguages() as $Language) {
  180. $languageList[$Language->getLanguageId()] = $Language->getNativeName();
  181. }
  182. asort($languageList);
  183. foreach ($data as $k => $v) {
  184. // clean user input
  185. if (!in_array($k, self::$m_html_allowed_fields)) {
  186. $data[$k] = camp_html_entity_decode_array($v);
  187. }
  188. }
  189. // load possible topic list
  190. foreach ($this->GetTopicTreeFlat() as $topicId => $topicName) {
  191. $topics[$topicId] = $topicName;
  192. }
  193. // get the topics used
  194. foreach ($this->getTopics() as $Topic) {
  195. $active_topics[$Topic->getTopicId()] = $Topic->getName($this->getLanguageId());
  196. }
  197. $mask = array(
  198. 'f_blog_id' => array(
  199. 'element' => 'f_blog_id',
  200. 'type' => 'hidden',
  201. 'constant' => $data['blog_id']
  202. ),
  203. 'language' => array(
  204. 'element' => 'Blog[fk_language_id]',
  205. 'type' => 'select',
  206. 'label' => getGS('Language'),
  207. 'default' => $data['fk_language_id'],
  208. 'options' => $languageList,
  209. 'required' => true
  210. ),
  211. 'title' => array(
  212. 'element' => 'Blog[title]',
  213. 'type' => 'text',
  214. 'label' => getGS('Title'),
  215. 'default' => $data['title'],
  216. 'required' => true
  217. ),
  218. 'tiny_mce' => array(
  219. 'element' => 'tiny_mce',
  220. 'text' => self::GetEditor('tiny_mce_box', $g_user, camp_session_get('TOL_Language', $data['fk_language_id'])),
  221. 'type' => 'static'
  222. ),
  223. 'info' => array(
  224. 'element' => 'Blog[info]',
  225. 'type' => 'textarea',
  226. 'label' => getGS('Info'),
  227. 'default' => $data['info'],
  228. 'required' => true,
  229. 'attributes'=> array('cols' => 86, 'rows' => 16, 'id' => 'tiny_mce_box')
  230. ),
  231. 'feature' => array(
  232. 'element' => 'Blog[feature]',
  233. 'type' => 'text',
  234. 'label' => getGS('Feature'),
  235. 'default' => $data['feature'],
  236. ),
  237. 'status' => array(
  238. 'element' => 'Blog[status]',
  239. 'type' => 'select',
  240. 'label' => getGS('Status'),
  241. 'default' => $data['status'],
  242. 'required' => true,
  243. 'options' => array(
  244. 'online' => getGS('online'),
  245. 'offline' => getGS('offline'),
  246. 'moderated' => getGS('moderated'),
  247. 'readonly' => getGS('read only'),
  248. ),
  249. ),
  250. 'admin_status' => array(
  251. 'element' => 'Blog[admin_status]',
  252. 'type' => 'select',
  253. 'label' => getGS('Admin status'),
  254. 'default' => $data['admin_status'],
  255. 'required' => true,
  256. 'options' => array(
  257. 'online' => getGS('online'),
  258. 'offline' => getGS('offline'),
  259. 'pending' => getGS('pending'),
  260. 'moderated' => getGS('moderated'),
  261. 'readonly' => getGS('read only'),
  262. ),
  263. ),
  264. 'owner' => array(
  265. 'element' => 'Blog[fk_user_id]',
  266. 'type' => 'select',
  267. 'label' => getGS('Owner'),
  268. 'default' => $data['fk_user_id'],
  269. 'options' => $ownerList,
  270. ),
  271. 'image' => array(
  272. 'element' => 'Blog_Image',
  273. 'type' => 'file',
  274. 'label' => getGS('Image (.jpg, .png, .gif)'),
  275. ),
  276. 'image_display' => array(
  277. 'element' => 'image_display',
  278. 'text' => '<img src="'.$data['images']['100x100'].'">',
  279. 'type' => 'static',
  280. 'groupit' => true
  281. ),
  282. 'image_remove' => array(
  283. 'element' => 'Blog_Image_remove',
  284. 'type' => 'checkbox',
  285. 'label' => getGS('Remove this image'),
  286. 'groupit' => true
  287. ),
  288. 'image_label' => array(
  289. 'element' => 'image_label',
  290. 'text' => getGS('Remove this image'),
  291. 'type' => 'static',
  292. 'groupit' => true
  293. ),
  294. 'image_group' => isset($data['images']['100x100']) ? array(
  295. 'group' => array('image_display', 'Blog_Image_remove', 'image_label'),
  296. ) : null,
  297. 'admin_remark' => array(
  298. 'element' => 'Blog[admin_remark]',
  299. 'type' => 'textarea',
  300. 'label' => getGS('Admin remark'),
  301. 'default' => $data['admin_remark'],
  302. 'attributes'=> array('cols' => 86, 'rows' => 10)
  303. ),
  304. 'reset' => array(
  305. 'element' => 'reset',
  306. 'type' => 'reset',
  307. 'label' => getGS('Reset'),
  308. 'groupit' => true
  309. ),
  310. 'xsubmit' => array(
  311. 'element' => 'xsubmit',
  312. 'type' => 'button',
  313. 'label' => getGS('Submit'),
  314. 'attributes'=> array('onclick' => 'tinyMCE.triggerSave(); if (this.form.onsubmit()) this.form.submit()'),
  315. 'groupit' => true
  316. ),
  317. 'cancel' => array(
  318. 'element' => 'cancel',
  319. 'type' => 'button',
  320. 'label' => getGS('Cancel'),
  321. 'attributes' => array('onClick' => 'window.close()'),
  322. 'groupit' => true
  323. ),
  324. 'buttons' => array(
  325. 'group' => array('cancel', 'reset', 'xsubmit')
  326. )
  327. );
  328. return $mask;
  329. }
  330. function getForm($p_target, $p_admin, $p_html=true)
  331. {
  332. require_once 'HTML/QuickForm.php';
  333. $mask = $this->getFormMask($p_owner, $p_admin);
  334. $form = new html_QuickForm('blog', 'post', $p_target, null, null, true);
  335. FormProcessor::parseArr2Form($form, $mask);
  336. if ($p_html) {
  337. return $form->toHTML();
  338. } else {
  339. require_once 'HTML/QuickForm/Renderer/Array.php';
  340. $renderer = new HTML_QuickForm_Renderer_Array(true, true);
  341. $form->accept($renderer);
  342. return $renderer->toArray();
  343. }
  344. }
  345. function store($p_admin, $p_user_id=null)
  346. {
  347. require_once 'HTML/QuickForm.php';
  348. $mask = $this->getFormMask($p_admin);
  349. $form = new html_QuickForm('blog', 'post', '', null, null, true);
  350. FormProcessor::parseArr2Form($form, $mask);
  351. if ($form->validate()){
  352. $data = $form->getSubmitValues(true);
  353. foreach ($data['Blog'] as $k => $v) {
  354. // clean user input
  355. if (!in_array($k, self::$m_html_allowed_fields)) {
  356. $data['Blog'][$k] = htmlspecialchars_array($v);
  357. }
  358. }
  359. if ($data['f_blog_id']) {
  360. foreach ($data['Blog'] as $k => $v) {
  361. $this->setProperty($k, $v);
  362. }
  363. if ($data['Blog_Image_remove']) {
  364. BlogImageHelper::RemoveImageDerivates('blog', $data['f_blog_id']);
  365. }
  366. if ($data['Blog_Image']) {
  367. BlogImageHelper::StoreImageDerivates('blog', $data['f_blog_id'], $data['Blog_Image']);
  368. }
  369. return true;
  370. } elseif ($this->create(
  371. isset($p_user_id) ? $p_user_id : $data['Blog']['fk_user_id'],
  372. $data['Blog']['fk_language_id'],
  373. $data['Blog']['title'],
  374. $data['Blog']['info'],
  375. $data['Blog']['request_text'],
  376. $data['Blog']['feature'])) {
  377. if ($data['Blog']['status']) {
  378. $this->setProperty('status', $data['Blog']['status']);
  379. }
  380. if ($p_admin && $data['Blog']['admin_status']) {
  381. $this->setProperty('admin_status', $data['Blog']['admin_status']);
  382. }
  383. if ($p_admin && $data['Blog']['admin_remark']) {
  384. $this->setProperty('admin_remark', $data['Blog']['admin_remark']);
  385. }
  386. if ($data['Blog_Image']) {
  387. BlogImageHelper::StoreImageDerivates('blog', $this->getProperty('blog_id'), $data['BlogEntry_Image']);
  388. }
  389. return true;
  390. }
  391. }
  392. return false;
  393. }
  394. /**
  395. * Get the blog identifier
  396. *
  397. * @return int
  398. */
  399. public function getId()
  400. {
  401. return $this->getProperty('blog_id');
  402. }
  403. /**
  404. * get the blog language id
  405. *
  406. * @return int
  407. */
  408. public function getLanguageId()
  409. {
  410. return $this->getProperty('fk_language_id');
  411. }
  412. public static function GetBlogLanguageId($p_blog_id)
  413. {
  414. $tmpBlog= new Blog($p_blog_id);
  415. return $tmpBlog->getProperty('fk_language_id');
  416. }
  417. static public function GetTopicTree($p_key = 'PLUGIN_BLOG_ROOT_TOPIC_ID')
  418. {
  419. $root_id = SystemPref::Get($p_key);
  420. $tree = Topic::GetTree((int)$root_id);
  421. return (array) $tree;
  422. }
  423. static public function GetTopicTreeFlat($p_key = 'PLUGIN_BLOG_ROOT_TOPIC_ID')
  424. {
  425. foreach (self::GetTopicTree($p_key) as $branch) {
  426. $flat[] = end($branch)->getTopicId();
  427. }
  428. return (array) $flat;
  429. }
  430. public function setTopics(array $p_topics=array())
  431. {
  432. // store the topics
  433. $allowed_topics = self::GetTopicTreeFlat();
  434. BlogTopic::DeleteBlogTopics($this->getId());
  435. foreach ($p_topics as $topic_id) {
  436. if (in_array($topic_id, $allowed_topics, true)) {
  437. $BlogTopic = new BlogTopic($this->m_data['blog_id'], $topic_id);
  438. $BlogTopic->create();
  439. }
  440. }
  441. }
  442. public function getTopics()
  443. {
  444. foreach (BlogTopic::getAssignments($this->m_data['blog_id']) as $BlogTopic) {
  445. $topics[] = $BlogTopic->getTopic();
  446. }
  447. return (array) $topics;
  448. }
  449. public static function GetMoodList($p_language_id)
  450. {
  451. foreach (Topic::GetTree((int)SystemPref::Get('PLUGIN_BLOG_ROOT_MOOD_ID')) as $path) {
  452. $currentTopic = camp_array_peek($path, false, -1);
  453. $name = $currentTopic->getName($p_language_id);
  454. if (empty($name)) {
  455. // Backwards compatibility
  456. $name = $currentTopic->getName(1);
  457. if (empty($name)) {
  458. continue;
  459. }
  460. }
  461. foreach ($path as $topicObj) {
  462. $name = $topicObj->getName($p_language_id);
  463. if (empty($name)) {
  464. $name = $topicObj->getName(1);
  465. if (empty($name)) {
  466. $name = "-----";
  467. }
  468. }
  469. $value = htmlspecialchars($name);
  470. }
  471. $selected = $currentTopic->getTopicId() == SystemPref::Get('PLUGIN_BLOG_ROOT_MOOD_ID') ? 'selected' : '';
  472. $options[$currentTopic->getTopicId()] = $value;
  473. }
  474. return (array)$options;
  475. }
  476. /**
  477. * If we modify the admin status,
  478. * the publish date is modified too.
  479. *
  480. * @param string $p_name
  481. * @param sring $p_value
  482. */
  483. function setProperty($p_name, $p_value)
  484. {
  485. /*
  486. if ($p_name == 'admin_status') {
  487. switch ($p_value) {
  488. case 'online':
  489. case 'moderated':
  490. case 'readonly':
  491. parent::setProperty('date', date('Y-m-d H:i:s'));
  492. break;
  493. case 'offline':
  494. case 'pending':
  495. parent::setProperty('date', null);
  496. break;
  497. }
  498. }
  499. */
  500. if ($p_name == 'topics') {
  501. $return = $this->setTopics($p_value);
  502. $CampCache = CampCache::singleton();
  503. $CampCache->clear('user');
  504. return $return;
  505. }
  506. if ($p_name == 'fk_language_id') {
  507. $this->onSetLanguage($p_value);
  508. }
  509. $return = parent::setProperty($p_name, $p_value);
  510. $CampCache = CampCache::singleton();
  511. $CampCache->clear('user');
  512. return $return;
  513. }
  514. private function onSetLanguage($p_language_id)
  515. {
  516. if ($p_language_id == $this->getLanguageId()) {
  517. return;
  518. }
  519. global $g_ado_db;
  520. $entryTbl = BlogEntry::$s_dbTableName;
  521. $commentTbl = BlogComment::$s_dbTableName;
  522. $queryStr1 = "UPDATE $entryTbl
  523. SET fk_language_id = $p_language_id
  524. WHERE fk_blog_id = {$this->getId()}";
  525. $g_ado_db->Execute($queryStr1);
  526. $queryStr1 = "UPDATE $commentTbl
  527. SET fk_language_id = $p_language_id
  528. WHERE fk_blog_id = {$this->getId()}";
  529. $g_ado_db->Execute($queryStr1);
  530. $CampCache = CampCache::singleton();
  531. $CampCache->clear('user');
  532. }
  533. /**
  534. * @param array p_dbColumns
  535. * @param object p_user The User object
  536. * @param int p_editorLanguage The current or selected language
  537. *
  538. * @return void
  539. */
  540. public static function GetEditor($p_box_id, $p_user, $p_editorLanguage)
  541. {
  542. global $Campsite;
  543. $stylesheetFile = '/admin/articles/article_stylesheet.css';
  544. /** STEP 2 ********************************************************
  545. * Now, what are the plugins you will be using in the editors
  546. * on this page. List all the plugins you will need, even if not
  547. * all the editors will use all the plugins.
  548. ******************************************************************/
  549. $plugins = array();
  550. if ($p_user->hasPermission('EditorCopyCutPaste')) {
  551. $plugins[] = 'paste';
  552. }
  553. if ($p_user->hasPermission('EditorFindReplace')) {
  554. $plugins[] = 'searchreplace';
  555. }
  556. if ($p_user->hasPermission('EditorEnlarge')) {
  557. $plugins[] = 'fullscreen';
  558. }
  559. if ($p_user->hasPermission('EditorTable')) {
  560. $plugins[] = 'table';
  561. }
  562. if ($p_user->hasPermission('EditorLink')) {
  563. $plugins[] = 'campsiteinternallink';
  564. }
  565. $plugins[] = 'drupalbreak';
  566. $plugins_list = implode(",", $plugins);
  567. $statusbar_location = "none";
  568. if ($p_user->hasPermission('EditorStatusBar')) {
  569. $statusbar_location = "bottom";
  570. }
  571. /** STEP 3 ********************************************************
  572. * We create a default configuration to be used by all the editors.
  573. * If you wish to configure some of the editors differently this
  574. * will be done in step 4.
  575. ******************************************************************/
  576. $toolbar1 = array();
  577. if ($p_user->hasPermission('EditorBold')) {
  578. $toolbar1[] = "bold";
  579. }
  580. if ($p_user->hasPermission('EditorItalic')) {
  581. $toolbar1[] = "italic";
  582. }
  583. if ($p_user->hasPermission('EditorUnderline')) {
  584. $toolbar1[] = "underline";
  585. }
  586. if ($p_user->hasPermission('EditorStrikethrough')) {
  587. $toolbar1[] = "strikethrough";
  588. }
  589. if ($p_user->hasPermission('EditorTextAlignment')) {
  590. $toolbar1[] = "|";
  591. $toolbar1[] = "justifyleft";
  592. $toolbar1[] = "justifycenter";
  593. $toolbar1[] = "justifyright";
  594. $toolbar1[] = "justifyfull";
  595. }
  596. if ($p_user->hasPermission('EditorIndent')) {
  597. $toolbar1[] = "|";
  598. $toolbar1[] = "outdent";
  599. $toolbar1[] = "indent";
  600. $toolbar1[] = "blockquote";
  601. }
  602. if ($p_user->hasPermission('EditorCopyCutPaste')) {
  603. $toolbar1[] = "|";
  604. $toolbar1[] = "copy";
  605. $toolbar1[] = "cut";
  606. $toolbar1[] = "paste";
  607. $toolbar1[] = "pasteword";
  608. }
  609. if ($p_user->hasPermission('EditorUndoRedo')) {
  610. $toolbar1[] = "|";
  611. $toolbar1[] = "undo";
  612. $toolbar1[] = "redo";
  613. }
  614. if ($p_user->hasPermission('EditorTextDirection')) {
  615. $toolbar1[] = "|";
  616. $toolbar1[] = "ltr";
  617. $toolbar1[] = "rtl";
  618. $toolbar1[] = "charmap";
  619. }
  620. if ($p_user->hasPermission('EditorLink')) {
  621. $toolbar1[] = "|";
  622. #$toolbar1[] = "campsiteinternallink";
  623. $toolbar1[] = "link";
  624. }
  625. if ($p_user->hasPermission('EditorSubhead')) {
  626. #$toolbar1[] = "campsite-subhead";
  627. }
  628. if ($p_user->hasPermission('EditorImage')) {
  629. $toolbar1[] = "image";
  630. }
  631. $toolbar1[] = "drupalbreak";
  632. if ($p_user->hasPermission('EditorSourceView')) {
  633. $toolbar1[] = "code";
  634. }
  635. if ($p_user->hasPermission('EditorEnlarge')) {
  636. $toolbar1[] = "fullscreen";
  637. }
  638. if ($p_user->hasPermission('EditorHorizontalRule')) {
  639. $toolbar1[] = "hr";
  640. }
  641. if ($p_user->hasPermission('EditorFontColor')) {
  642. $toolbar1[] = "forecolor";
  643. $toolbar1[] = "backcolor";
  644. }
  645. if ($p_user->hasPermission('EditorSubscript')) {
  646. $toolbar1[] = "sub";
  647. }
  648. if ($p_user->hasPermission('EditorSuperscript')) {
  649. $toolbar1[] = "sup";
  650. }
  651. if ($p_user->hasPermission('EditorFindReplace')) {
  652. $toolbar1[] = "|";
  653. $toolbar1[] = "search";
  654. $toolbar1[] = "replace";
  655. }
  656. $toolbar2 = array();
  657. // Slice up the first toolbar if it is too long.
  658. if (count($toolbar1) > 31) {
  659. $toolbar2 = array_splice($toolbar1, 31);
  660. }
  661. // This is to put the bulleted and numbered list controls
  662. // on the most appropriate line of the toolbar.
  663. if ($p_user->hasPermission('EditorListBullet') && $p_user->hasPermission('EditorListNumber') && count($toolbar1) < 19) {
  664. $toolbar1[] = "|";
  665. $toolbar1[] = "bullist";
  666. $toolbar1[] = "numlist";
  667. } elseif ($p_user->hasPermission('EditorListBullet') && !$p_user->hasPermission('EditorListNumber') && count($toolbar1) < 31) {
  668. $toolbar1[] = "|";
  669. $toolbar1[] = "bullist";
  670. } elseif (!$p_user->hasPermission('EditorListBullet') && $p_user->hasPermission('EditorListNumber') && count($toolbar1) < 20) {
  671. $toolbar1[] = "|";
  672. $toolbar1[] = "numlist";
  673. } else {
  674. $hasSeparator = false;
  675. if ($p_user->hasPermission('EditorListBullet')) {
  676. $toolbar2[] = "|";
  677. $toolbar2[] = "bullist";
  678. $hasSeparator = true;
  679. }
  680. if ($p_user->hasPermission('EditorListNumber')) {
  681. if (!$hasSeparator) {
  682. $toolbar2[] = "|";
  683. }
  684. $toolbar2[] = "numlist";
  685. }
  686. }
  687. if ($p_user->hasPermission('EditorFontFace')) {
  688. $toolbar2[] = "|";
  689. $toolbar2[] = "styleselect";
  690. $toolbar2[] = "formatselect";
  691. $toolbar2[] = "fontselect";
  692. }
  693. if ($p_user->hasPermission('EditorFontSize')) {
  694. $toolbar2[] = "fontsizeselect";
  695. }
  696. if ($p_user->hasPermission('EditorTable')) {
  697. $toolbar3[] = "tablecontrols";
  698. }
  699. $theme_buttons1 = (count($toolbar1) > 0) ? implode(',', $toolbar1) : '';
  700. $theme_buttons2 = (count($toolbar2) > 0) ? implode(',', $toolbar2) : '';
  701. $theme_buttons3 = (count($toolbar3) > 0) ? implode(',', $toolbar3) : '';
  702. ob_start();
  703. ?>
  704. <!-- TinyMCE -->
  705. <script type="text/javascript" src="/javascript/tinymce/tiny_mce.js"></script>
  706. <script type="text/javascript">
  707. function CampsiteSubhead(ed) {
  708. element = ed.dom.getParent(ed.selection.getNode(), 'span');
  709. if (element && ed.dom.getAttrib(element, 'class') == 'campsite_subhead') {
  710. return false;
  711. } else {
  712. html = ed.selection.getContent({format : 'text'});
  713. ed.selection.setContent('<span class="campsite_subhead">' + html + '</span>');
  714. }
  715. } // fn CampsiteSubhead
  716. // Default skin
  717. tinyMCE.init({
  718. // General options
  719. language : "<?php p($p_editorLanguage); ?>",
  720. mode : "exact",
  721. elements : "<?php p($p_box_id); ?>",
  722. theme : "advanced",
  723. plugins : "<?php p($plugins_list); ?>",
  724. forced_root_block : "",
  725. relative_urls : false,
  726. // Theme options
  727. theme_advanced_buttons1 : "<?php p($theme_buttons1); ?>",
  728. theme_advanced_buttons2 : "<?php p($theme_buttons2); ?>",
  729. theme_advanced_buttons3 : "<?php p($theme_buttons3); ?>",
  730. theme_advanced_toolbar_location : "top",
  731. theme_advanced_toolbar_align : "left",
  732. theme_advanced_resizing : false,
  733. theme_advanced_statusbar_location: "<?php p($statusbar_location); ?>",
  734. // Example content CSS (should be your site CSS)
  735. content_css : "<?php echo $stylesheetFile; ?>",
  736. // Drop lists for link/image/media/template dialogs
  737. template_external_list_url : "lists/template_list.js",
  738. external_link_list_url : "lists/link_list.js",
  739. external_image_list_url : "lists/image_list.js",
  740. media_external_list_url : "lists/media_list.js",
  741. // paste options
  742. paste_use_dialog: false,
  743. paste_auto_cleanup_on_paste: true,
  744. paste_convert_headers_to_strong: true,
  745. paste_remove_spans: true,
  746. paste_remove_styles: true,
  747. setup : function(ed) {
  748. ed.onKeyUp.add(function(ed, l) {
  749. var idx = ed.id.lastIndexOf('_');
  750. var buttonId = ed.id.substr(0, idx);
  751. buttonEnable('save_' + buttonId);
  752. });
  753. }
  754. });
  755. </script>
  756. <!-- /TinyMCE -->
  757. <?php
  758. $output = ob_get_clean();
  759. return $output;
  760. } // fn editor_load_tinymce
  761. /////////////////// Special template engine methods below here /////////////////////////////
  762. /**
  763. * Gets an blog list based on the given parameters.
  764. *
  765. * @param array $p_parameters
  766. * An array of ComparisonOperation objects
  767. * @param string $p_order
  768. * An array of columns and directions to order by
  769. * @param integer $p_start
  770. * The record number to start the list
  771. * @param integer $p_limit
  772. * The offset. How many records from $p_start will be retrieved.
  773. *
  774. * @return array $issuesList
  775. * An array of Issue objects
  776. */
  777. public static function GetList($p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count)
  778. {
  779. global $g_ado_db;
  780. if (!is_array($p_parameters)) {
  781. return null;
  782. }
  783. // adodb::selectLimit() interpretes -1 as unlimited
  784. if ($p_limit == 0) {
  785. $p_limit = -1;
  786. }
  787. $selectClauseObj = new SQLSelectClause();
  788. // sets the where conditions
  789. foreach ($p_parameters as $param) {
  790. $comparisonOperation = self::ProcessListParameters($param);
  791. $leftOperand = strtolower($comparisonOperation['left']);
  792. if ($leftOperand == 'matchalltopics') {
  793. // set the matchAllTopics flag
  794. $matchAllTopics = true;
  795. } elseif ($leftOperand == 'topic') {
  796. // add the topic to the list of match/do not match topics depending
  797. // on the operator
  798. if ($comparisonOperation['symbol'] == '=') {
  799. $hasTopics[] = $comparisonOperation['right'];
  800. } else {
  801. $hasNotTopics[] = $comparisonOperation['right'];
  802. }
  803. } else {
  804. $comparisonOperation = self::ProcessListParameters($param);
  805. if (empty($comparisonOperation)) {
  806. continue;
  807. }
  808. $whereCondition = $comparisonOperation['left'] . ' '
  809. . $comparisonOperation['symbol'] . " '"
  810. . $comparisonOperation['right'] . "' ";
  811. $selectClauseObj->addWhere($whereCondition);
  812. }
  813. }
  814. if (count($hasTopics) > 0) {
  815. if ($matchAllTopics) {
  816. foreach ($hasTopics as $topicId) {
  817. $sqlQuery = self::BuildTopicSelectClause(array($topicId));
  818. $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery )";
  819. $selectClauseObj->addWhere($whereCondition);
  820. }
  821. } else {
  822. $sqlQuery = self::BuildTopicSelectClause($hasTopics);
  823. $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery )";
  824. $selectClauseObj->addWhere($whereCondition);
  825. }
  826. }
  827. if (count($hasNotTopics) > 0) {
  828. $sqlQuery = self::BuildTopicSelectClause($hasNotTopics, true);
  829. $whereCondition = "plugin_blog_blog.blog_id IN (\n$sqlQuery )";
  830. $selectClauseObj->addWhere($whereCondition);
  831. }
  832. // sets the columns to be fetched
  833. $tmpBlog = new Blog();
  834. $columnNames = $tmpBlog->getColumnNames(true);
  835. foreach ($columnNames as $columnName) {
  836. $selectClauseObj->addColumn($columnName);
  837. }
  838. // sets the main table for the query
  839. $mainTblName = $tmpBlog->getDbTableName();
  840. $selectClauseObj->setTable($mainTblName);
  841. unset($tmpBlog);
  842. if (is_array($p_order)) {
  843. $order = self::ProcessListOrder($p_order);
  844. // sets the order condition if any
  845. foreach ($order as $orderField=>$orderDirection) {
  846. $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
  847. }
  848. }
  849. $sqlQuery = $selectClauseObj->buildQuery();
  850. // count all available results
  851. $countRes = $g_ado_db->Execute($sqlQuery);
  852. $p_count = $countRes->recordCount();
  853. //get tlimited rows
  854. $blogRes = $g_ado_db->SelectLimit($sqlQuery, $p_limit, $p_start);
  855. // builds the array of blog objects
  856. $blogsList = array();
  857. while ($blog = $blogRes->FetchRow()) {
  858. $blogObj = new Blog($blog['blog_id']);
  859. if ($blogObj->exists()) {
  860. $blogsList[] = $blogObj;
  861. }
  862. }
  863. return $blogsList;
  864. } // fn GetList
  865. /**
  866. * Processes a paremeter (condition) coming from template tags.
  867. *
  868. * @param array $p_param
  869. * The array of parameters
  870. *
  871. * @return array $comparisonOperation
  872. * The array containing processed values of the condition
  873. */
  874. private static function ProcessListParameters($p_param)
  875. {
  876. $conditionOperation = array();
  877. $leftOperand = strtolower($p_param->getLeftOperand());
  878. $conditionOperation['left'] = BlogsList::$s_parameters[$leftOperand]['field'];
  879. switch ($leftOperand) {
  880. case 'feature':
  881. $conditionOperation['symbol'] = 'LIKE';
  882. $conditionOperation['right'] = '%'.$p_param->getRightOperand().'%';
  883. break;
  884. case 'matchalltopics':
  885. $conditionOperation['symbol'] = '=';
  886. $conditionOperation['right'] = 'true';
  887. break;
  888. case 'topic':
  889. $conditionOperation['right'] = (string)$p_param->getRightOperand();
  890. break;
  891. default:
  892. $conditionOperation['right'] = (string)$p_param->getRightOperand();
  893. break;
  894. }
  895. if (!isset($conditionOperation['symbol'])) {
  896. $operatorObj = $p_param->getOperator();
  897. $conditionOperation['symbol'] = $operatorObj->getSymbol('sql');
  898. }
  899. return $conditionOperation;
  900. } // fn ProcessListParameters
  901. /**
  902. * Processes an order directive coming from template tags.
  903. *
  904. * @param array $p_order
  905. * The array of order directives
  906. *
  907. * @return array
  908. * The array containing processed values of the condition
  909. */
  910. private static function ProcessListOrder(array $p_order)
  911. {
  912. $order = array();
  913. foreach ($p_order as $field=>$direction) {
  914. $dbField = BlogsList::$s_parameters[substr($field, 2)]['field'];
  915. if (!is_null($dbField)) {
  916. $direction = !empty($direction) ? $direction : 'asc';
  917. }
  918. $order[$dbField] = $direction;
  919. }
  920. if (count($order) == 0) {
  921. $order['blog_id'] = 'asc';
  922. }
  923. return $order;
  924. } // fn ProcessListOrder
  925. /**
  926. * Returns a select query for obtaining the blogs that have the given topics
  927. *
  928. * @param array $p_TopicIds
  929. * @param array $p_typeAttributes
  930. * @param bool $p_negate
  931. * @return string
  932. */
  933. private static function BuildTopicSelectClause(array $p_TopicIds, $p_negate = false)
  934. {
  935. $notCondition = $p_negate ? ' NOT' : '';
  936. $selectClause = ' SELECT fk_blog_id FROM '.BlogTopic::$$s_dbTableName.' WHERE fk_topic_id'
  937. . "$notCondition IN (" . implode(', ', $p_TopicIds) . ")\n";
  938. return $selectClause;
  939. }
  940. }
  941. ?>