BxCmtsMy.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreSamples Samples
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section comments Comments
  12. */
  13. /**
  14. * DB Queries for Vote Sample.
  15. INSERT INTO `sys_objects_vote`(`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES
  16. ('sample_cmts_vote', 'sample_cmts_votes', 'sample_cmts_votes_track', '604800', '1', '1', '1', '1', 'sample_cmts', 'cmt_id', 'cmt_rate', 'cmt_votes', '', '');
  17. CREATE TABLE IF NOT EXISTS `sample_cmts_votes` (
  18. `object_id` int(11) NOT NULL default '0',
  19. `count` int(11) NOT NULL default '0',
  20. `sum` int(11) NOT NULL default '0',
  21. UNIQUE KEY `object_id` (`object_id`)
  22. ) ENGINE=MYISAM DEFAULT CHARSET=utf8;
  23. CREATE TABLE IF NOT EXISTS `sample_cmts_votes_track` (
  24. `object_id` int(11) NOT NULL default '0',
  25. `author_id` int(11) NOT NULL default '0',
  26. `author_nip` int(11) unsigned NOT NULL default '0',
  27. `value` tinyint(4) NOT NULL default '0',
  28. `date` int(11) NOT NULL default '0',
  29. KEY `vote` (`object_id`, `author_nip`)
  30. ) ENGINE=MYISAM DEFAULT CHARSET=utf8;
  31. */
  32. /**
  33. * DB Queries for Comments Sample.
  34. INSERT INTO `sys_objects_cmts` (`ID`, `Name`, `Table`, `CharsPostMin`, `CharsPostMax`, `CharsDisplayMax`, `Nl2br`, `PerView`, `PerViewReplies`, `BrowseType`, `IsBrowseSwitch`, `PostFormPosition`, `NumberOfLevels`, `IsDisplaySwitch`, `IsRatable`, `ViewingThreshold`, `IsOn`, `RootStylePrefix`, `BaseUrl`, `ObjectVote`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldTitle`, `TriggerFieldComments`, `ClassName`, `ClassFile`) VALUES
  35. (1, 'sample', 'sample_cmts', 1, 5000, 1000, 1, 5, 3, 'tail', 1, 'bottom', 1, 1, 1, -3, 1, 'cmt', 'samples/comments.php', 'sample_cmts_vote', 'sample_cmts_trigger', 'id', 'title', 'comments', 'BxCmtsMy', 'samples/BxCmtsMy.php');
  36. CREATE TABLE IF NOT EXISTS `sample_cmts` (
  37. `cmt_id` int(11) NOT NULL AUTO_INCREMENT,
  38. `cmt_parent_id` int(11) NOT NULL DEFAULT '0',
  39. `cmt_vparent_id` int(11) NOT NULL DEFAULT '0',
  40. `cmt_object_id` int(11) NOT NULL DEFAULT '0',
  41. `cmt_author_id` int(10) unsigned NOT NULL DEFAULT '0',
  42. `cmt_level` int(11) NOT NULL DEFAULT '0',
  43. `cmt_text` text NOT NULL,
  44. `cmt_rate` int(11) NOT NULL DEFAULT '0',
  45. `cmt_votes` int(11) NOT NULL DEFAULT '0',
  46. `cmt_time` int(11) unsigned NOT NULL DEFAULT '0',
  47. `cmt_replies` int(11) NOT NULL DEFAULT '0',
  48. PRIMARY KEY (`cmt_id`),
  49. KEY `cmt_object_id` (`cmt_object_id`,`cmt_parent_id`)
  50. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  51. Note: 'sample_cmts_trigger' table is needed just to check comments counter. In real integration it should be your main content table.
  52. CREATE TABLE IF NOT EXISTS `sample_cmts_trigger` (
  53. `id` int(11) NOT NULL AUTO_INCREMENT,
  54. `title` varchar(64) NOT NULL DEFAULT '0',
  55. `comments` int(11) NOT NULL DEFAULT '0',
  56. PRIMARY KEY (`id`)
  57. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  58. INSERT INTO `sample_cmts_trigger` (`id`, `title`, `comments`) VALUES
  59. (1, 'Sample Comments', 0);
  60. */
  61. /**
  62. * DB Queries for Privacy Sample.
  63. *
  64. ALTER TABLE `sample_cmts` ADD `allow_view_to` INT( 11 ) NOT NULL DEFAULT '3';
  65. INSERT INTO `sys_objects_privacy`(`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
  66. ('comments_view', 'comments', 'view', '', '3', 'sample_cmts', 'cmt_id', 'cmt_author_id', '', '');
  67. */
  68. require_once(BX_DOL_DIR_STUDIO_INC . "utils.inc.php");
  69. class BxCmtsMy extends BxTemplCmts
  70. {
  71. function BxCmtsMy( $sSystem, $iId, $iInit = 1 )
  72. {
  73. parent::BxTemplCmts( $sSystem, $iId, $iInit );
  74. }
  75. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  76. {
  77. $iCmtId = is_array($mixedCmt) ? (int)$mixedCmt['cmt_id'] : (int)$mixedCmt;
  78. $oPrivacy = BxDolPrivacy::getObjectInstance('comments_view');
  79. if(!$oPrivacy->check($iCmtId))
  80. return '';
  81. return parent::getComment($mixedCmt, $aBp, $aDp);
  82. }
  83. protected function _getFormObject($sAction, $iId)
  84. {
  85. $oForm = parent::_getFormObject($sAction, $iId);
  86. $sPrivacyObject = 'comments_view';
  87. $sFieldName = BxDolPrivacy::getFieldName($sPrivacyObject);
  88. $aFieldDescriptor = BxDolPrivacy::getGroupChooser($sPrivacyObject);
  89. $aFieldDescriptor['caption'] = '';
  90. $oForm->aInputs = bx_array_insert_after(array($sFieldName => $aFieldDescriptor), $oForm->aInputs, 'cmt_text');
  91. return $oForm;
  92. }
  93. }
  94. /** @} */