1
0

BxBaseModGeneralModule.php 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. protected $_aSearchableNamesExcept;
  19. protected $_aFormParams;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_aSearchableNamesExcept = array(
  25. 'allow_view_to'
  26. );
  27. $this->_aFormParams = array(
  28. 'display' => false,
  29. 'dynamic_mode' => false,
  30. 'ajax_mode' => false,
  31. 'absolute_action_url' => false,
  32. 'visibility_autoselect' => false,
  33. 'context_id' => 0,
  34. 'custom' => array()
  35. );
  36. }
  37. // ====== ACTIONS METHODS
  38. public function actionRss ()
  39. {
  40. $aArgs = func_get_args();
  41. $this->_rss($aArgs);
  42. }
  43. public function actionGetCreatePostForm()
  44. {
  45. $sName = $this->_oConfig->getName();
  46. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  47. $aParams = array_merge($this->_aFormParams, $aParams);
  48. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  49. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  50. if(empty($mixedResponse))
  51. return echoJson(array());
  52. else if(is_array($mixedResponse)) {
  53. $mixedResponse['module'] = $sName;
  54. return echoJson($mixedResponse);
  55. }
  56. return echoJson(array(
  57. 'module' => $sName,
  58. 'content' => $mixedResponse
  59. ));
  60. }
  61. // ====== SERVICE METHODS
  62. public function serviceIsSafeService($s)
  63. {
  64. $sService = bx_gen_method_name($s);
  65. $aSafeServices = $this->serviceGetSafeServices();
  66. return isset($aSafeServices[$sService]);
  67. }
  68. public function serviceGetSafeServices()
  69. {
  70. return array(
  71. // other
  72. 'ModuleIcon' => '',
  73. 'GetLink' => '',
  74. // browse
  75. 'GetSearchResultUnit' => '',
  76. 'Browse' => '',
  77. 'BrowseFeatured' => '',
  78. 'BrowseFavorite' => '',
  79. // forms
  80. 'GetCreatePostForm' => '',
  81. 'EntityEdit' => '',
  82. 'EntityDelete' => '',
  83. // page blocks
  84. 'EntityTextBlock' => '',
  85. 'EntityInfo' => '',
  86. 'EntityInfoFull' => '',
  87. 'EntityInfoExtended' => '',
  88. 'EntityLocation' => '',
  89. 'EntityComments' => '',
  90. 'EntityAttachments' => '',
  91. // menu
  92. 'EntityAllActions' => '',
  93. 'EntityActions' => '',
  94. 'EntitySocialSharing' => '',
  95. 'MyEntriesActions' => '',
  96. );
  97. }
  98. /**
  99. * @page service Service Calls
  100. * @section bx_base_general Base General
  101. * @subsection bx_base_general-other Other
  102. * @subsubsection bx_base_general-module_icon module_icon
  103. *
  104. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  105. *
  106. * Get module icon as CSS class name with FontAwesome icon name class and color class
  107. *
  108. * @see BxBaseModGeneralModule::serviceModuleIcon
  109. */
  110. /**
  111. * @ref bx_base_general-module_icon "module_icon"
  112. */
  113. public function serviceModuleIcon ()
  114. {
  115. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  116. }
  117. public function serviceGetAuthor ($iContentId)
  118. {
  119. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  120. return $mixedResult !== false ? (int)$mixedResult : 0;
  121. }
  122. public function serviceGetPrivacyView ($iContentId)
  123. {
  124. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  125. }
  126. public function serviceGetDateAdded ($iContentId)
  127. {
  128. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  129. return $mixedResult !== false ? (int)$mixedResult : 0;
  130. }
  131. public function serviceGetDateChanged ($iContentId)
  132. {
  133. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  134. return $mixedResult !== false ? (int)$mixedResult : 0;
  135. }
  136. /**
  137. * @page service Service Calls
  138. * @section bx_base_general Base General
  139. * @subsection bx_base_general-other Other
  140. * @subsubsection bx_base_general-get_link get_link
  141. *
  142. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  143. *
  144. * Get URL for the specified content.
  145. * @param $iContentId content id
  146. *
  147. * @see BxBaseModGeneralModule::serviceGetLink
  148. */
  149. /**
  150. * @ref bx_base_general-get_link "get_link"
  151. */
  152. public function serviceGetLink ($iContentId)
  153. {
  154. $CNF = &$this->_oConfig->CNF;
  155. if(empty($CNF['URI_VIEW_ENTRY']))
  156. return '';
  157. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  158. if(empty($aContentInfo))
  159. return '';
  160. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  161. }
  162. public function serviceGetTitle ($iContentId)
  163. {
  164. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  165. return $mixedResult !== false ? $mixedResult : '';
  166. }
  167. public function serviceGetText ($iContentId)
  168. {
  169. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  170. if (false === $mixedResult)
  171. return '';
  172. $CNF = &$this->_oConfig->CNF;
  173. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  174. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  175. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  176. }
  177. return $mixedResult;
  178. }
  179. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  180. {
  181. $CNF = &$this->_oConfig->CNF;
  182. $aContentInfo = $this->_getFields($iContentId);
  183. if(empty($aContentInfo))
  184. return array();
  185. if(!$bSearchableFieldsOnly)
  186. return $aContentInfo;
  187. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  188. return array();
  189. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  190. if(empty($aFields))
  191. return array();
  192. $aResult = array();
  193. foreach($aFields as $sField)
  194. if(isset($aContentInfo[$sField]))
  195. $aResult[$sField] = $aContentInfo[$sField];
  196. return $aResult;
  197. }
  198. /**
  199. * @page service Service Calls
  200. * @section bx_base_general Base General
  201. * @subsection bx_base_general-browsing Browsing
  202. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  203. *
  204. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  205. *
  206. * Get browsing unit for the specified content
  207. * @param $iContentId content id
  208. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  209. *
  210. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  211. */
  212. /**
  213. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  214. */
  215. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  216. {
  217. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  218. if(empty($aContentInfo))
  219. return '';
  220. if(empty($sUnitTemplate))
  221. $sUnitTemplate = 'unit.html';
  222. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  223. }
  224. public function serviceGetAll ($aParams = array())
  225. {
  226. if(empty($aParams) || !is_array($aParams))
  227. $aParams = array('type' => 'all');
  228. return $this->_oDb->getEntriesBy($aParams);
  229. }
  230. public function serviceGetAllByAuthor ($iProfileId)
  231. {
  232. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  233. }
  234. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  235. {
  236. $CNF = &$this->_oConfig->CNF;
  237. if(empty($CNF['OBJECT_FORM_ENTRY']))
  238. return array();
  239. $aResult = array();
  240. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  241. $aResult[$CNF['FIELD_AUTHOR']] = array(
  242. 'type' => 'text_auto',
  243. 'caption' => $CNF['T']['form_field_author'],
  244. 'info' => '',
  245. 'value' => '',
  246. 'values' => '',
  247. 'pass' => ''
  248. );
  249. $aInputs = array();
  250. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  251. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  252. $aInputs = array_merge($aInputs, $oForm->aInputs);
  253. }
  254. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  255. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  256. $aInputs = array_merge($aInputs, $oForm->aInputs);
  257. }
  258. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  259. $aInputs = array_merge($aInputs, $aInputsAdd);
  260. foreach($aInputs as $aInput){
  261. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  262. $aField = array(
  263. 'type' => $aInput['type'],
  264. 'caption_system' => $aInput['caption_system_src'],
  265. 'caption' => $aInput['caption_src'],
  266. 'info' => $aInput['info_src'],
  267. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  268. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  269. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  270. );
  271. if(isset($aInput['search_type']))
  272. $aField['search_type'] = $aInput['search_type'];
  273. $aResult[$aInput['name']] = $aField;
  274. }
  275. }
  276. return $aResult;
  277. }
  278. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  279. {
  280. if(empty($aParams) || !is_array($aParams))
  281. return array();
  282. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  283. }
  284. public function serviceGetSearchableFields ($aInputsAdd = array())
  285. {
  286. $CNF = $this->_oConfig->CNF;
  287. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  288. return array();
  289. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  290. if(!$oForm)
  291. return array();
  292. $aInputs = $oForm->aInputs;
  293. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  294. $aInputs = array_merge($aInputs, $aInputsAdd);
  295. $aTextTypes = array('text', 'textarea');
  296. $aTextFields = array();
  297. foreach($aInputs as $r)
  298. if(in_array($r['type'], $aTextTypes))
  299. $aTextFields[$r['name']] = $r['caption'];
  300. return $aTextFields;
  301. }
  302. public function serviceManageTools($sType = 'common')
  303. {
  304. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  305. if(!$oGrid)
  306. return '';
  307. $CNF = &$this->_oConfig->CNF;
  308. $sMenu = '';
  309. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  310. $oPermalink = BxDolPermalinks::getInstance();
  311. $aMenuItems = array();
  312. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  313. $aMenuItems[] = array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1);
  314. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  315. $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
  316. if(count($aMenuItems) > 1) {
  317. $oMenu = new BxTemplMenu(array(
  318. 'template' => 'menu_vertical.html',
  319. 'menu_items' => $aMenuItems
  320. ), $this->_oTemplate);
  321. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  322. $sMenu = $oMenu->getCode();
  323. }
  324. }
  325. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  326. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  327. }
  328. $this->_oTemplate->addCss(array('manage_tools.css'));
  329. $this->_oTemplate->addJs(array('manage_tools.js'));
  330. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  331. return array(
  332. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  333. 'menu' => $sMenu
  334. );
  335. }
  336. public function serviceGetMenuAddonManageTools()
  337. {
  338. return 0;
  339. }
  340. public function serviceGetMenuAddonManageToolsProfileStats()
  341. {
  342. return 0;
  343. }
  344. /**
  345. * @page service Service Calls
  346. * @section bx_base_general Base General
  347. * @subsection bx_base_general-browsing Browsing
  348. * @subsubsection bx_base_general-browse browse
  349. *
  350. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  351. *
  352. * Universal browse method.
  353. * @param $aParams custom browse params, possible params are the following:
  354. * - mode - browse mode, such as 'recent', 'featured', etc
  355. * - params - custom params to browse method, for example 'unit_view' can be passed here
  356. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  357. * - empty_message - display or not "empty" message when there is no content
  358. * - ajax_paginate - use AJAX paginate or not
  359. *
  360. * @see BxBaseModGeneralModule::serviceBrowse
  361. */
  362. /**
  363. * @ref bx_base_general-browse "browse"
  364. */
  365. public function serviceBrowse ($aParams = array())
  366. {
  367. $aDefaults = array (
  368. 'mode' => 'recent',
  369. 'params' => false,
  370. 'design_box' => BX_DB_PADDING_DEF,
  371. 'empty_message' => false,
  372. 'ajax_paginate' => true,
  373. 'class_search_result' => 'SearchResult'
  374. );
  375. $aParams = array_merge($aDefaults, $aParams);
  376. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  377. }
  378. /**
  379. * @page service Service Calls
  380. * @section bx_base_general Base General
  381. * @subsection bx_base_general-browsing Browsing
  382. * @subsubsection bx_base_general-browse_featured browse_featured
  383. *
  384. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  385. *
  386. * Display featured entries
  387. * @param $sUnitView browseing unity view,
  388. * such as: full, extended, gallery, showcase
  389. * @param $bEmptyMessage display or not "empty" message when there is no content
  390. * @param $bAjaxPaginate use AJAX paginate or not
  391. *
  392. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  393. */
  394. /**
  395. * @ref bx_base_general-browse_featured "browse_featured"
  396. */
  397. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  398. {
  399. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  400. }
  401. /**
  402. * @page service Service Calls
  403. * @section bx_base_general Base General
  404. * @subsection bx_base_general-browsing Browsing
  405. * @subsubsection bx_base_general-browse_favorite browse_favorite
  406. *
  407. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  408. *
  409. * Display entries whoch were added to favorite list by some member
  410. * @param $iProfileId profile ID
  411. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  412. *
  413. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  414. */
  415. /**
  416. * @ref bx_base_general-browse_favorite "browse_favorite"
  417. */
  418. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  419. {
  420. $oProfile = null;
  421. if((int)$iProfileId)
  422. $oProfile = BxDolProfile::getInstance($iProfileId);
  423. if(!$oProfile && bx_get('profile_id') !== false)
  424. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  425. if(!$oProfile)
  426. $oProfile = BxDolProfile::getInstance();
  427. if(!$oProfile)
  428. return '';
  429. $bEmptyMessage = false;
  430. if(isset($aParams['empty_message'])) {
  431. $bEmptyMessage = (bool)$aParams['empty_message'];
  432. unset($aParams['empty_message']);
  433. }
  434. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  435. }
  436. /**
  437. * Display entries posted into particular context
  438. * @return HTML string
  439. */
  440. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  441. {
  442. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  443. }
  444. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  445. {
  446. if(!$sParamVal)
  447. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  448. if(!$sParamVal)
  449. return '';
  450. $bEmptyMessage = true;
  451. if(isset($aParams['empty_message'])) {
  452. $bEmptyMessage = (bool)$aParams['empty_message'];
  453. unset($aParams['empty_message']);
  454. }
  455. $bAjaxPaginate = true;
  456. if(isset($aParams['ajax_paginate'])) {
  457. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  458. unset($aParams['ajax_paginate']);
  459. }
  460. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  461. }
  462. public function serviceFormsHelper ()
  463. {
  464. bx_import('FormsEntryHelper', $this->_aModule);
  465. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  466. return new $sClass($this);
  467. }
  468. /**
  469. * Add entry using provided fields' values.
  470. * @return array with result: 'code' is 0 on success or non-zero on error, 'message' is error message in case of error, 'content' is content info array in case of success
  471. */
  472. public function serviceEntityAdd ($iProfile, $aValues)
  473. {
  474. bx_import('FormsEntryHelper', $this->_aModule);
  475. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  476. $oFormsHelper = new $sClass($this);
  477. return $oFormsHelper->addData($iProfile, $aValues);
  478. }
  479. /**
  480. * Perform redirect after content creation
  481. * @return nothing, rediret header is sent
  482. */
  483. public function serviceRedirectAfterAdd($aContentInfo)
  484. {
  485. bx_import('FormsEntryHelper', $this->_aModule);
  486. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  487. $oFormsHelper = new $sClass($this);
  488. $oFormsHelper->redirectAfterAdd($aContentInfo);
  489. }
  490. /**
  491. * Get form object for add, edit, view or delete the content
  492. * @param $sType 'add', 'edit', 'view' or 'delete'
  493. * @param $aParams optional array with parameters(display name, etc)
  494. * @return form object or false on error
  495. */
  496. public function serviceGetObjectForm ($sType, $aParams = array())
  497. {
  498. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  499. return false;
  500. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  501. $bContext = $mixedContextId !== false;
  502. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  503. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  504. return false;
  505. $CNF = &$this->_oConfig->CNF;
  506. bx_import('FormsEntryHelper', $this->_aModule);
  507. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  508. $oFormsHelper = new $sClass($this);
  509. $sParamsKey = 'ajax_mode';
  510. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  511. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  512. $sParamsKey = 'absolute_action_url';
  513. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  514. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  515. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  516. $sFunc = 'getObjectForm' . ucfirst($sType);
  517. $oForm = $oFormsHelper->$sFunc($sDisplay);
  518. $sKey = 'FIELD_ALLOW_VIEW_TO';
  519. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  520. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  521. if(!$bContext || $bContextOwner) {
  522. $iGc = 0;
  523. $iKeyGh = false;
  524. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  525. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  526. if($iKeyGh !== false && $iGc == 0) {
  527. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  528. $iKeyGh = false;
  529. if($aValue['type'] == 'group_end')
  530. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  531. }
  532. if($aValue['type'] == 'group_header') {
  533. $iGc = 0;
  534. $iKeyGh = $iKey;
  535. }
  536. continue;
  537. }
  538. //--- Show 'Public' privacy group only in Public post form.
  539. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  540. $iGc += 1;
  541. continue;
  542. }
  543. //--- Show a default privacy groups in Profile (for Owner) post form.
  544. if($bContextOwner && (int)$aValue['key'] >= 0) {
  545. $iGc += 1;
  546. continue;
  547. }
  548. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  549. }
  550. }
  551. else {
  552. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  553. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  554. }
  555. }
  556. bx_alert('system', 'get_object_form', 0, 0, array(
  557. 'module' => $this->_oConfig->getName(),
  558. 'type' => $sType,
  559. 'params' => $aParams,
  560. 'form' => &$oForm
  561. ));
  562. return $oForm;
  563. }
  564. /**
  565. * Create entry form
  566. * @return HTML string
  567. */
  568. public function serviceEntityCreate ($sParams = false)
  569. {
  570. $bParamsArray = is_array($sParams);
  571. $sDisplay = is_string($sParams) ? $sParams : false;
  572. if($bParamsArray && !empty($sParams['display']))
  573. $sDisplay = $sParams['display'];
  574. bx_import('FormsEntryHelper', $this->_aModule);
  575. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  576. $oFormsHelper = new $sClass($this);
  577. if($bParamsArray && isset($sParams['dynamic_mode']))
  578. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  579. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  580. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  581. echoJson($mixedResult);
  582. exit;
  583. }
  584. return $mixedResult;
  585. }
  586. /**
  587. * @page service Service Calls
  588. * @section bx_base_general Base General
  589. * @subsection bx_base_general-forms Forms
  590. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  591. *
  592. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  593. *
  594. * Get content creation form
  595. * @param $aParams additional parameters array:
  596. * context_id, ajax_mode, absolute_action_url, displays
  597. *
  598. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  599. */
  600. /**
  601. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  602. */
  603. public function serviceGetCreatePostForm($aParams = array())
  604. {
  605. $aParams = array_merge($this->_aFormParams, $aParams);
  606. $oForm = $this->serviceGetObjectForm('add', $aParams);
  607. if(!$oForm)
  608. return '';
  609. return $this->serviceEntityCreate($aParams);
  610. }
  611. /**
  612. * @page service Service Calls
  613. * @section bx_base_general Base General
  614. * @subsection bx_base_general-forms Forms
  615. * @subsubsection bx_base_general-entity_edit entity_edit
  616. *
  617. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  618. *
  619. * Get content edit form
  620. * @param $iContentId content ID
  621. * @param $sDisplay optional form display name
  622. *
  623. * @see BxBaseModGeneralModule::serviceEntityEdit
  624. */
  625. /**
  626. * @ref bx_base_general-entity_edit "entity_edit"
  627. */
  628. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  629. {
  630. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  631. }
  632. /**
  633. * @page service Service Calls
  634. * @section bx_base_general Base General
  635. * @subsection bx_base_general-forms Forms
  636. * @subsubsection bx_base_general-entity_delete entity_delete
  637. *
  638. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  639. *
  640. * Get content delete form
  641. * @param $iContentId content ID
  642. *
  643. * @see BxBaseModGeneralModule::serviceEntityDelete
  644. */
  645. /**
  646. * @ref bx_base_general-entity_delete "entity_delete"
  647. */
  648. public function serviceEntityDelete ($iContentId = 0)
  649. {
  650. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  651. }
  652. /**
  653. * @page service Service Calls
  654. * @section bx_base_general Base General
  655. * @subsection bx_base_general-page_blocks Page Blocks
  656. * @subsubsection bx_base_general-entity_text_block entity_text_block
  657. *
  658. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  659. *
  660. * Get content text/description
  661. * @param $iContentId content ID
  662. *
  663. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  664. */
  665. /**
  666. * @ref bx_base_general-entity_text_block "entity_text_block"
  667. */
  668. public function serviceEntityTextBlock ($iContentId = 0)
  669. {
  670. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  671. }
  672. /**
  673. * @page service Service Calls
  674. * @section bx_base_general Base General
  675. * @subsection bx_base_general-page_blocks Page Blocks
  676. * @subsubsection bx_base_general-entity_info entity_info
  677. *
  678. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  679. *
  680. * Get content info
  681. * @param $iContentId content ID
  682. *
  683. * @see BxBaseModGeneralModule::serviceEntityInfo
  684. */
  685. /**
  686. * @ref bx_base_general-entity_info "entity_info"
  687. */
  688. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  689. {
  690. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  691. }
  692. /**
  693. * @page service Service Calls
  694. * @section bx_base_general Base General
  695. * @subsection bx_base_general-page_blocks Page Blocks
  696. * @subsubsection bx_base_general-entity_info_full entity_info_full
  697. *
  698. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  699. *
  700. * Get full content info
  701. * @param $iContentId content ID
  702. *
  703. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  704. */
  705. /**
  706. * @ref bx_base_general-entity_info_full "entity_info_full"
  707. */
  708. public function serviceEntityInfoFull ($iContentId = 0)
  709. {
  710. $CNF = &$this->_oConfig->CNF;
  711. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  712. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  713. }
  714. /**
  715. * @page service Service Calls
  716. * @section bx_base_general Base General
  717. * @subsection bx_base_general-page_blocks Page Blocks
  718. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  719. *
  720. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  721. *
  722. * Get extended content info
  723. * @param $iContentId content ID
  724. *
  725. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  726. */
  727. /**
  728. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  729. */
  730. public function serviceEntityInfoExtended ($iContentId = 0)
  731. {
  732. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  733. }
  734. /**
  735. * @page service Service Calls
  736. * @section bx_base_general Base General
  737. * @subsection bx_base_general-page_blocks Page Blocks
  738. * @subsubsection bx_base_general-entity_location entity_location
  739. *
  740. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  741. *
  742. * Get content location
  743. * @param $iContentId content ID
  744. *
  745. * @see BxBaseModGeneralModule::serviceEntityLocation
  746. */
  747. /**
  748. * @ref bx_base_general-entity_location "entity_location"
  749. */
  750. public function serviceEntityLocation ($iContentId = 0)
  751. {
  752. $iContentId = $this->_getContent($iContentId, false);
  753. if($iContentId === false)
  754. return false;
  755. return $this->_oTemplate->entryLocation ($iContentId);
  756. }
  757. /**
  758. * @page service Service Calls
  759. * @section bx_base_general Base General
  760. * @subsection bx_base_general-page_blocks Page Blocks
  761. * @subsubsection bx_base_general-entity_comments entity_comments
  762. *
  763. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  764. *
  765. * Get content comments
  766. * @param $iContentId content ID
  767. *
  768. * @see BxBaseModGeneralModule::serviceEntityComments
  769. */
  770. /**
  771. * @ref bx_base_general-entity_comments "entity_comments"
  772. */
  773. public function serviceEntityComments ($iContentId = 0)
  774. {
  775. $CNF = &$this->_oConfig->CNF;
  776. if(empty($CNF['OBJECT_COMMENTS']))
  777. return '';
  778. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  779. }
  780. /**
  781. * @page service Service Calls
  782. * @section bx_base_general Base General
  783. * @subsection bx_base_general-page_blocks Page Blocks
  784. * @subsubsection bx_base_general-entity_attachments entity_attachments
  785. *
  786. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  787. *
  788. * Get content attachments
  789. * @param $iContentId content ID
  790. *
  791. * @see BxBaseModGeneralModule::serviceEntityAttachments
  792. */
  793. /**
  794. * @ref bx_base_general-entity_attachments "entity_attachments"
  795. */
  796. public function serviceEntityAttachments ($iContentId = 0)
  797. {
  798. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  799. }
  800. /**
  801. * Delete content entry
  802. * @param $iContentId content id
  803. * @return error message or empty string on success
  804. */
  805. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  806. {
  807. bx_import('FormsEntryHelper', $this->_aModule);
  808. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  809. $oFormsHelper = new $sClass($this);
  810. return $oFormsHelper->$sFuncDelete($iContentId);
  811. }
  812. /**
  813. * @page service Service Calls
  814. * @section bx_base_general Base General
  815. * @subsection bx_base_general-menu Menu
  816. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  817. *
  818. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  819. *
  820. * My entries actions menu
  821. * @param $iProfileId profiles ID,
  822. * if omitted it try to get it from 'profile_id' GET param
  823. *
  824. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  825. */
  826. /**
  827. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  828. */
  829. public function serviceMyEntriesActions ($iProfileId = 0)
  830. {
  831. $CNF = &$this->_oConfig->CNF;
  832. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  833. return false;
  834. if (!$iProfileId)
  835. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  836. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  837. return false;
  838. if ($iProfileId != $this->_iProfileId)
  839. return false;
  840. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  841. return $oMenu ? $oMenu->getCode() : false;
  842. }
  843. /**
  844. * @page service Service Calls
  845. * @section bx_base_general Base General
  846. * @subsection bx_base_general-menu Menu
  847. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  848. *
  849. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  850. *
  851. * Entry actions and social sharing actions
  852. * @param $mixedContent content ID
  853. * @param $aParams additional params
  854. *
  855. * @see BxBaseModGeneralModule::serviceEntityAllActions
  856. */
  857. /**
  858. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  859. */
  860. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  861. {
  862. $CNF = &$this->_oConfig->CNF;
  863. if(!empty($mixedContent)) {
  864. if(!is_array($mixedContent))
  865. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  866. }
  867. else {
  868. $mixedContent = $this->_getContent();
  869. if($mixedContent === false)
  870. return false;
  871. }
  872. list($iContentId, $aContentInfo) = $mixedContent;
  873. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  874. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  875. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  876. if(empty($sObjectMenu))
  877. return false;
  878. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  879. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  880. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  881. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  882. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  883. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  884. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  885. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  886. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  887. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  888. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  889. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  890. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  891. $aMarkers = array(
  892. 'id' => $iContentId,
  893. 'module' => $this->_oConfig->getName(),
  894. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  895. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  896. 'img_url' => ''
  897. );
  898. if(!empty($iEntryThumb)) {
  899. if(!empty($sObjectTranscoder))
  900. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  901. else if(!empty($sObjectStorage))
  902. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  903. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  904. if(!empty($sImageUrl))
  905. $aMarkers['img_url'] = $sImageUrl;
  906. }
  907. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  908. if(!$oActions)
  909. return false;
  910. $oActions->setContentId($iContentId);
  911. $oActions->addMarkers($aMarkers);
  912. return $this->_oTemplate->entryAllActions($oActions->getCode());
  913. }
  914. /**
  915. * @page service Service Calls
  916. * @section bx_base_general Base General
  917. * @subsection bx_base_general-menu Menu
  918. * @subsubsection bx_base_general-entity_actions entity_actions
  919. *
  920. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  921. *
  922. * Entry actions, without social sharing actions
  923. * @param $iContentId content ID
  924. *
  925. * @see BxBaseModGeneralModule::serviceEntityActions
  926. */
  927. /**
  928. * @ref bx_base_general-entity_actions "entity_actions"
  929. */
  930. public function serviceEntityActions ($iContentId = 0)
  931. {
  932. $iContentId = $this->_getContent($iContentId, false);
  933. if($iContentId === false)
  934. return false;
  935. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  936. return $oMenu ? $oMenu->getCode() : false;
  937. }
  938. /**
  939. * @page service Service Calls
  940. * @section bx_base_general Base General
  941. * @subsection bx_base_general-menu Menu
  942. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  943. *
  944. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  945. *
  946. * Entry social sharing actions
  947. * @param $mixedContent content ID or array with integer content ID and
  948. * array with content info, or false
  949. * @param $aParams array with additional custom params
  950. * which may overwrite some default values
  951. *
  952. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  953. */
  954. /**
  955. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  956. */
  957. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  958. {
  959. if(!empty($mixedContent)) {
  960. if(!is_array($mixedContent))
  961. $mixedContent = array((int)$mixedContent, array());
  962. }
  963. else {
  964. $mixedContent = $this->_getContent();
  965. if($mixedContent === false)
  966. return false;
  967. }
  968. list($iContentId, $aContentInfo) = $mixedContent;
  969. $CNF = &$this->_oConfig->CNF;
  970. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  971. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  972. $sUri = $CNF['URI_VIEW_ENTRY'];
  973. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  974. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  975. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  976. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  977. $aMarkers = array(
  978. 'id' => $iContentId,
  979. 'module' => $this->_aModule['name'],
  980. 'url' => BX_DOL_URL_ROOT . $sUrl,
  981. 'title' => $sTitle,
  982. );
  983. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  984. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  985. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  986. if ($iIdThumb) {
  987. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  988. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  989. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  990. $sStorage = $CNF['OBJECT_STORAGE'];
  991. if(!empty($sTranscoder))
  992. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  993. else if(!empty($sStorage))
  994. $o = BxDolStorage::getObjectInstance($sStorage);
  995. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  996. if($sImgUrl)
  997. $aMarkers['img_url'] = $sImgUrl;
  998. }
  999. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1000. $oMenu->addMarkers($aMarkers);
  1001. $sMenu = $oMenu->getCode();
  1002. if(empty($sMenu))
  1003. return '';
  1004. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1005. 'menu' => $sMenu
  1006. ));
  1007. }
  1008. /**
  1009. * Entry context block
  1010. */
  1011. public function serviceEntityContext ($iContentId = 0)
  1012. {
  1013. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1014. }
  1015. /**
  1016. * Blocks for lables tree browsing
  1017. */
  1018. public function serviceGetLablesTree()
  1019. {
  1020. $aBreadcrumbs = array();
  1021. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1022. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1023. }
  1024. public function serviceGetLablesBreadcrumbs()
  1025. {
  1026. if (bx_get('label')){
  1027. $aBreadcrumbs = array();
  1028. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1029. $aLabels = array();
  1030. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1031. $aLabels[] = array(
  1032. 'value' => $aLabel['value'],
  1033. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1034. );
  1035. }
  1036. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1037. }
  1038. return '';
  1039. }
  1040. public function serviceBrowseByLabel()
  1041. {
  1042. $CNF = &$this->_oConfig->CNF;
  1043. if (empty($CNF['OBJECT_METATAGS']))
  1044. return '';
  1045. $sMode = 'recent';
  1046. $sClassSearchResult ='SearchResult';
  1047. bx_import($sClassSearchResult, $this->_aModule['name']);
  1048. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1049. $o = new $sClass($sMode, false);
  1050. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1051. $o->setDisplayEmptyMsg(true);
  1052. $o->setAjaxPaginate(false);
  1053. $o->setUnitParams(array('context' => $sMode));
  1054. if (bx_get('label')){
  1055. $iLabelId = (int)bx_get('label');
  1056. $oLabel = BxDolLabel::getInstance();
  1057. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1058. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1059. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1060. }
  1061. if ($o->isError)
  1062. return '';
  1063. if ($s = $o->processing())
  1064. return $s;
  1065. else
  1066. return '';
  1067. }
  1068. /**
  1069. * Data for Notifications module
  1070. */
  1071. public function serviceGetNotificationsData()
  1072. {
  1073. $sModule = $this->_aModule['name'];
  1074. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1075. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1076. $sEventPrivacy = '';
  1077. $aResult = array(
  1078. 'handlers' => array(
  1079. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1080. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1081. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  1082. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1083. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1084. array('group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1085. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1086. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1087. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1088. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1089. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1090. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1091. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1092. ),
  1093. 'settings' => array(
  1094. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  1095. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1096. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1097. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1098. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1099. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1100. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1101. ),
  1102. 'alerts' => array(
  1103. array('unit' => $sModule, 'action' => 'added'),
  1104. array('unit' => $sModule, 'action' => 'edited'),
  1105. array('unit' => $sModule, 'action' => 'deleted'),
  1106. array('unit' => $sModule, 'action' => 'commentPost'),
  1107. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1108. array('unit' => $sModule, 'action' => 'replyPost'),
  1109. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1110. array('unit' => $sModule, 'action' => 'doVote'),
  1111. array('unit' => $sModule, 'action' => 'undoVote'),
  1112. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1113. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1114. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1115. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1116. )
  1117. );
  1118. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1119. $aResult = array_merge($aResult, array(
  1120. 'handlers' => array(
  1121. array('group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module', 'module_event_privacy' => ''),
  1122. array('group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module', 'module_event_privacy' => ''),
  1123. ),
  1124. 'settings' => array(
  1125. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1126. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1127. ),
  1128. 'alerts' => array(
  1129. array('unit' => $sModule, 'action' => 'publish_failed'),
  1130. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1131. )
  1132. ));
  1133. }
  1134. return $aResult;
  1135. }
  1136. /**
  1137. * Entry post for Notifications module
  1138. */
  1139. public function serviceGetNotificationsPost($aEvent)
  1140. {
  1141. $CNF = &$this->_oConfig->CNF;
  1142. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1143. if(empty($aContentInfo) || !is_array($aContentInfo))
  1144. return array();
  1145. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1146. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1147. return array(
  1148. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1149. 'entry_url' => $sEntryUrl,
  1150. 'entry_caption' => $sEntryCaption,
  1151. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1152. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1153. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1154. /*
  1155. * Custom settings for email and/or push notifications can be provided here.
  1156. * Only necessary parts of 'settings' array can be used.
  1157. *
  1158. 'settings' => array(
  1159. 'email' => array(
  1160. 'template' => '', //--- custom email template
  1161. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1162. 'subject' => '' //--- custom email subject
  1163. ),
  1164. 'push' => array(
  1165. 'subject' => '' //--- custom push notification subject
  1166. )
  1167. )
  1168. */
  1169. );
  1170. }
  1171. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1172. {
  1173. return $this->serviceGetNotificationsPost($aEvent);
  1174. }
  1175. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1176. {
  1177. return $this->serviceGetNotificationsPost($aEvent);
  1178. }
  1179. /**
  1180. * Entry post comment for Notifications module
  1181. */
  1182. public function serviceGetNotificationsComment($aEvent)
  1183. {
  1184. $CNF = &$this->_oConfig->CNF;
  1185. $iContentId = (int)$aEvent['object_id'];
  1186. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1187. if(empty($aContentInfo) || !is_array($aContentInfo))
  1188. return array();
  1189. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1190. if(!$oComment || !$oComment->isEnabled())
  1191. return array();
  1192. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1193. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1194. return array(
  1195. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1196. 'entry_url' => $sEntryUrl,
  1197. 'entry_caption' => $sEntryCaption,
  1198. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1199. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1200. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1201. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1202. );
  1203. }
  1204. /**
  1205. * Entry post reply for Notifications module
  1206. */
  1207. public function serviceGetNotificationsReply($aEvent)
  1208. {
  1209. $CNF = &$this->_oConfig->CNF;
  1210. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1211. if(!$oComment || !$oComment->isEnabled())
  1212. return array();
  1213. $iParentId = (int)$aEvent['object_id'];
  1214. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1215. if(empty($aParentInfo) || !is_array($aParentInfo))
  1216. return array();
  1217. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1218. $oComment->init($iObjectId);
  1219. return array(
  1220. 'object_id' => $iObjectId,
  1221. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1222. 'entry_url' => $oComment->getViewUrl($iParentId),
  1223. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1224. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1225. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1226. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1227. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1228. );
  1229. }
  1230. /**
  1231. * Entry post vote for Notifications module
  1232. */
  1233. public function serviceGetNotificationsVote($aEvent)
  1234. {
  1235. $CNF = &$this->_oConfig->CNF;
  1236. $iContentId = (int)$aEvent['object_id'];
  1237. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1238. if(empty($aContentInfo) || !is_array($aContentInfo))
  1239. return array();
  1240. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1241. if(!$oVote || !$oVote->isEnabled())
  1242. return array();
  1243. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1244. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1245. return array(
  1246. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1247. 'entry_url' => $sEntryUrl,
  1248. 'entry_caption' => $sEntryCaption,
  1249. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1250. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1251. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1252. );
  1253. }
  1254. /**
  1255. * Entry post vote for Notifications module
  1256. */
  1257. public function serviceGetNotificationsReaction($aEvent)
  1258. {
  1259. $CNF = &$this->_oConfig->CNF;
  1260. $iContentId = (int)$aEvent['object_id'];
  1261. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1262. if(empty($aContentInfo) || !is_array($aContentInfo))
  1263. return array();
  1264. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1265. if(!$oReaction || !$oReaction->isEnabled())
  1266. return array();
  1267. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1268. if(empty($aSubentry) || !is_array($aSubentry))
  1269. return array();
  1270. $aSubentrySampleParams = array();
  1271. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1272. if(!empty($aReaction['title']))
  1273. $aSubentrySampleParams[] = $aReaction['title'];
  1274. else
  1275. $aSubentrySampleParams[] = '_undefined';
  1276. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1277. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1278. return array(
  1279. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1280. 'entry_url' => $sEntryUrl,
  1281. 'entry_caption' => $sEntryCaption,
  1282. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1283. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1284. 'subentry_sample_params' => $aSubentrySampleParams,
  1285. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1286. );
  1287. }
  1288. /**
  1289. * Entry post score -> vote up for Notifications module
  1290. */
  1291. public function serviceGetNotificationsScoreUp($aEvent)
  1292. {
  1293. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1294. }
  1295. /**
  1296. * Entry post score -> vote up for Notifications module
  1297. */
  1298. public function serviceGetNotificationsScoreDown($aEvent)
  1299. {
  1300. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1301. }
  1302. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1303. {
  1304. $CNF = &$this->_oConfig->CNF;
  1305. $iContentId = (int)$aEvent['object_id'];
  1306. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1307. if(empty($aContentInfo) || !is_array($aContentInfo))
  1308. return array();
  1309. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1310. if(!$oScore || !$oScore->isEnabled())
  1311. return array();
  1312. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1313. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1314. return array(
  1315. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1316. 'entry_url' => $sEntryUrl,
  1317. 'entry_caption' => $sEntryCaption,
  1318. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1319. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1320. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1321. );
  1322. }
  1323. /**
  1324. * Data for Timeline module
  1325. */
  1326. public function serviceGetTimelineData()
  1327. {
  1328. $sModule = $this->_aModule['name'];
  1329. return array(
  1330. 'handlers' => array(
  1331. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  1332. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1333. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1334. ),
  1335. 'alerts' => array(
  1336. array('unit' => $sModule, 'action' => 'added'),
  1337. array('unit' => $sModule, 'action' => 'edited'),
  1338. array('unit' => $sModule, 'action' => 'deleted'),
  1339. )
  1340. );
  1341. }
  1342. /**
  1343. * Entry post for Timeline module
  1344. */
  1345. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1346. {
  1347. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1348. if(empty($aContentInfo) || !is_array($aContentInfo))
  1349. return false;
  1350. $CNF = &$this->_oConfig->CNF;
  1351. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1352. return false;
  1353. $iUserId = $this->getUserId();
  1354. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1355. $iAuthorIdAbs = abs($iAuthorId);
  1356. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id']))) && $iAuthorIdAbs != $iUserId)
  1357. return false;
  1358. //--- Views
  1359. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1360. $aViews = array();
  1361. if ($oViews && $oViews->isEnabled())
  1362. $aViews = array(
  1363. 'system' => $CNF['OBJECT_VIEWS'],
  1364. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1365. 'count' => $aContentInfo['views']
  1366. );
  1367. //--- Votes
  1368. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1369. $aVotes = array();
  1370. if ($oVotes && $oVotes->isEnabled())
  1371. $aVotes = array(
  1372. 'system' => $CNF['OBJECT_VOTES'],
  1373. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1374. 'count' => $aContentInfo['votes']
  1375. );
  1376. //--- Reactions
  1377. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1378. $aReactions = array();
  1379. if ($oReactions && $oReactions->isEnabled())
  1380. $aReactions = array(
  1381. 'system' => $CNF['OBJECT_REACTIONS'],
  1382. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1383. 'count' => $aContentInfo['rvotes']
  1384. );
  1385. //--- Scores
  1386. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1387. $aScores = array();
  1388. if ($oScores && $oScores->isEnabled())
  1389. $aScores = array(
  1390. 'system' => $CNF['OBJECT_SCORES'],
  1391. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1392. 'score' => $aContentInfo['score']
  1393. );
  1394. //--- Reports
  1395. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1396. $aReports = array();
  1397. if ($oReports && $oReports->isEnabled())
  1398. $aReports = array(
  1399. 'system' => $CNF['OBJECT_REPORTS'],
  1400. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1401. 'count' => $aContentInfo['reports']
  1402. );
  1403. //--- Comments
  1404. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1405. $aComments = array();
  1406. if($oCmts && $oCmts->isEnabled())
  1407. $aComments = array(
  1408. 'system' => $CNF['OBJECT_COMMENTS'],
  1409. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1410. 'count' => $aContentInfo['comments']
  1411. );
  1412. //--- Title & Description
  1413. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1414. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1415. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1416. $iOwnerId = $iAuthorIdAbs;
  1417. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1418. $iOwnerId = abs($aEvent['object_privacy_view']);
  1419. $bCache = true;
  1420. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1421. if(isset($aContent['_cache'])) {
  1422. $bCache = (bool)$aContent['_cache'];
  1423. unset($aContent['_cache']);
  1424. }
  1425. return array(
  1426. '_cache' => $bCache,
  1427. 'owner_id' => $iOwnerId,
  1428. 'object_owner_id' => $iAuthorId,
  1429. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1430. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1431. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1432. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1433. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1434. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1435. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1436. 'views' => $aViews,
  1437. 'votes' => $aVotes,
  1438. 'reactions' => $aReactions,
  1439. 'scores' => $aScores,
  1440. 'reports' => $aReports,
  1441. 'comments' => $aComments,
  1442. 'title' => $sTitle, //may be empty.
  1443. 'description' => '' //may be empty.
  1444. );
  1445. }
  1446. public function serviceGetTimelinePostAllowedView($aEvent)
  1447. {
  1448. $iContentId = (int)$aEvent['object_id'];
  1449. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1450. if(empty($aContentInfo) || !is_array($aContentInfo))
  1451. return _t('_sys_txt_access_denied');
  1452. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1453. }
  1454. /**
  1455. * Check particular action permission without content
  1456. * @param $sAction action to check, for example: Browse, Add
  1457. * @param $iContentId content ID
  1458. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1459. */
  1460. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1461. {
  1462. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1463. if (!method_exists($this, $sMethod))
  1464. return _t('_sys_request_method_not_found_cpt');
  1465. return $this->$sMethod($isPerformAction);
  1466. }
  1467. /**
  1468. * Check particular action permission with content
  1469. * @param $sAction action to check, for example: View, Edit
  1470. * @param $iContentId content ID
  1471. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1472. */
  1473. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1474. {
  1475. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1476. return _t('_sys_request_page_not_found_cpt');
  1477. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1478. if (!method_exists($this, $sMethod))
  1479. return _t('_sys_request_method_not_found_cpt');
  1480. return $this->$sMethod($aContentInfo, $isPerformAction);
  1481. }
  1482. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1483. {
  1484. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1485. }
  1486. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1487. {
  1488. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1489. }
  1490. public function serviceGetContentOwnerProfileId ($iContentId)
  1491. {
  1492. $CNF = &$this->_oConfig->CNF;
  1493. // file owner must be author of the content or profile itself in case of profile based module
  1494. if ($iContentId) {
  1495. $sModule = $this->getName();
  1496. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1497. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1498. }
  1499. else {
  1500. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1501. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1502. }
  1503. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1504. }
  1505. else {
  1506. $iProfileId = bx_get_logged_profile_id();
  1507. }
  1508. return $iProfileId;
  1509. }
  1510. // ====== PERMISSION METHODS
  1511. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1512. {
  1513. if (!$iProfileId)
  1514. $iProfileId = $this->_iProfileId;
  1515. $CNF = &$this->_oConfig->CNF;
  1516. // moderator and owner always have access
  1517. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  1518. return CHECK_ACTION_RESULT_ALLOWED;
  1519. // check ACL
  1520. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  1521. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1522. return $aCheck[CHECK_ACTION_MESSAGE];
  1523. // check privacy
  1524. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  1525. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1526. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1527. return _t('_sys_access_denied_to_private_content');
  1528. }
  1529. // check alert to allow custom checks
  1530. $mixedResult = null;
  1531. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1532. if($mixedResult !== null)
  1533. return $mixedResult;
  1534. return CHECK_ACTION_RESULT_ALLOWED;
  1535. }
  1536. public function checkAllowedSetThumb ($iContentId = 0)
  1537. {
  1538. return CHECK_ACTION_RESULT_ALLOWED;
  1539. }
  1540. /**
  1541. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1542. */
  1543. public function checkAllowedBrowse ()
  1544. {
  1545. // check alert to allow custom checks
  1546. $mixedResult = null;
  1547. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1548. if($mixedResult !== null)
  1549. return $mixedResult;
  1550. return CHECK_ACTION_RESULT_ALLOWED;
  1551. }
  1552. /**
  1553. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1554. */
  1555. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1556. {
  1557. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1558. }
  1559. /**
  1560. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1561. */
  1562. public function checkAllowedAdd ($isPerformAction = false)
  1563. {
  1564. // check ACL
  1565. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1566. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1567. return $aCheck[CHECK_ACTION_MESSAGE];
  1568. return CHECK_ACTION_RESULT_ALLOWED;
  1569. }
  1570. /**
  1571. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1572. */
  1573. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1574. {
  1575. // moderator and owner always have access
  1576. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1577. return CHECK_ACTION_RESULT_ALLOWED;
  1578. return _t('_sys_txt_access_denied');
  1579. }
  1580. /**
  1581. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1582. */
  1583. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1584. {
  1585. // moderator always has access
  1586. if ($this->_isModerator($isPerformAction))
  1587. return CHECK_ACTION_RESULT_ALLOWED;
  1588. // check ACL
  1589. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1590. if (($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1591. return CHECK_ACTION_RESULT_ALLOWED;
  1592. return _t('_sys_txt_access_denied');
  1593. }
  1594. /**
  1595. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1596. */
  1597. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  1598. {
  1599. // admin always has access
  1600. if (isAdmin())
  1601. return CHECK_ACTION_RESULT_ALLOWED;
  1602. // check ACL
  1603. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1604. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1605. return $aCheck[CHECK_ACTION_MESSAGE];
  1606. return CHECK_ACTION_RESULT_ALLOWED;
  1607. }
  1608. /**
  1609. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1610. */
  1611. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1612. {
  1613. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1614. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1615. return CHECK_ACTION_RESULT_ALLOWED;
  1616. return _t('_sys_txt_access_denied');
  1617. }
  1618. /**
  1619. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1620. */
  1621. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1622. {
  1623. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1624. }
  1625. /**
  1626. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1627. */
  1628. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1629. {
  1630. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1631. }
  1632. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1633. {
  1634. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1635. return MsgBox($sMsg);
  1636. bx_import($sClassSearchResult, $this->_aModule);
  1637. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1638. $o = new $sClass($sMode, $aParams);
  1639. $o->setDesignBoxTemplateId($iDesignBox);
  1640. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1641. $o->setAjaxPaginate($bAjaxPaginate);
  1642. $o->setUnitParams(array('context' => $sMode));
  1643. if ($o->isError)
  1644. return '';
  1645. if ($s = $o->processing())
  1646. return $s;
  1647. else
  1648. return '';
  1649. }
  1650. // ====== COMMON METHODS
  1651. public function alertAfterAdd($aContentInfo) {}
  1652. public function alertAfterEdit($aContentInfo) {}
  1653. public function onPublished($iContentId) {}
  1654. public function onFailed($iContentId) {}
  1655. public function processMetasAdd($iContentId)
  1656. {
  1657. $CNF = &$this->_oConfig->CNF;
  1658. if(empty($CNF['OBJECT_METATAGS']))
  1659. return;
  1660. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1661. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1662. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1663. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1664. if(!$bContentInfo)
  1665. return;
  1666. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1667. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  1668. $sKey = 'FIELD_LOCATION';
  1669. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1670. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1671. if(!empty($aLocation) && is_array($aLocation))
  1672. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1673. }
  1674. $sKey = 'FIELD_LABELS';
  1675. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1676. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1677. if(!empty($aLabels) && is_array($aLabels))
  1678. foreach ($aLabels as $sLabel)
  1679. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1680. }
  1681. }
  1682. public function processMetasEdit($iContentId, $oForm)
  1683. {
  1684. $CNF = &$this->_oConfig->CNF;
  1685. if(empty($CNF['OBJECT_METATAGS']))
  1686. return;
  1687. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1688. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1689. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1690. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1691. if(!$bContentInfo)
  1692. return;
  1693. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1694. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  1695. $sKey = 'FIELD_LOCATION';
  1696. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1697. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1698. if(!empty($aLocation) && is_array($aLocation))
  1699. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1700. }
  1701. $sKey = 'FIELD_LABELS';
  1702. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1703. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1704. if(!empty($aLabels) && is_array($aLabels))
  1705. foreach ($aLabels as $sLabel)
  1706. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1707. }
  1708. }
  1709. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1710. {
  1711. if(empty($aTranscoders))
  1712. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1713. $CNF = &$this->_oConfig->CNF;
  1714. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1715. return false;
  1716. $iId = (int)$aContentInfo[$CNF[$sField]];
  1717. foreach($aTranscoders as $sTranscoder)
  1718. if(!empty($CNF[$sTranscoder]))
  1719. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1720. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1721. }
  1722. public function getProfileId()
  1723. {
  1724. return bx_get_logged_profile_id();
  1725. }
  1726. public function getProfileInfo($iUserId = 0)
  1727. {
  1728. $oProfile = $this->getObjectUser($iUserId);
  1729. $oAccount = null;
  1730. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1731. $oAccount = $oProfile->getAccountObject();
  1732. $bAccount = !empty($oAccount);
  1733. return array(
  1734. 'id' => $oProfile->id(),
  1735. 'name' => $oProfile->getDisplayName(),
  1736. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1737. 'link' => $oProfile->getUrl(),
  1738. 'icon' => $oProfile->getIcon(),
  1739. 'thumb' => $oProfile->getThumb(),
  1740. 'avatar' => $oProfile->getAvatar(),
  1741. 'unit' => $oProfile->getUnit(),
  1742. 'active' => $oProfile->isActive(),
  1743. );
  1744. }
  1745. public function getObjectUser($iUserId = 0)
  1746. {
  1747. bx_import('BxDolProfile');
  1748. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1749. return $oProfile;
  1750. }
  1751. public function getObjectFavorite($sSystem = '', $iId = 0)
  1752. {
  1753. $CNF = &$this->_oConfig->CNF;
  1754. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1755. $sSystem = $CNF['OBJECT_FAVORITES'];
  1756. if(empty($sSystem))
  1757. return false;
  1758. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1759. if(!$oFavorite || !$oFavorite->isEnabled())
  1760. return false;
  1761. return $oFavorite;
  1762. }
  1763. public function getUserId()
  1764. {
  1765. return isLogged() ? bx_get_logged_profile_id() : 0;
  1766. }
  1767. public function getUserIp()
  1768. {
  1769. return getVisitorIP();
  1770. }
  1771. public function getUserInfo($iUserId = 0)
  1772. {
  1773. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1774. return array(
  1775. $oProfile->getDisplayName(),
  1776. $oProfile->getUrl(),
  1777. $oProfile->getThumb(),
  1778. $oProfile->getUnit(),
  1779. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1780. );
  1781. }
  1782. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1783. {
  1784. $CNF = &$this->_oConfig->CNF;
  1785. // default visible settings
  1786. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1787. return false;
  1788. if (!empty($aItem['visibility_custom'])) {
  1789. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1790. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1791. return false;
  1792. }
  1793. // get custom function name to check menu item visibility
  1794. $sFuncCheckAccess = false;
  1795. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1796. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1797. // check custom visibility settings defined in module config class
  1798. if(!isset($aContentInfo))
  1799. $aContentInfo = array();
  1800. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1801. return false;
  1802. return true;
  1803. }
  1804. public function _isModerator ($isPerformAction = false)
  1805. {
  1806. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1807. }
  1808. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  1809. {
  1810. $CNF = &$this->_oConfig->CNF;
  1811. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  1812. $AuditParams = array(
  1813. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1814. 'context_profile_id' => $iContextId,
  1815. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  1816. 'data' => ($bIsSaveData ? $aContentInfo : array())
  1817. );
  1818. if ($iContextId > 0)
  1819. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  1820. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  1821. return $AuditParams;
  1822. }
  1823. // ====== PROTECTED METHODS
  1824. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1825. {
  1826. $iContentId = $this->_getContent($iContentId, false);
  1827. if($iContentId === false)
  1828. return false;
  1829. bx_import('FormsEntryHelper', $this->_aModule);
  1830. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1831. $oFormsHelper = new $sClass($this);
  1832. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1833. }
  1834. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1835. {
  1836. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1837. if($mixedContent === false)
  1838. return false;
  1839. list($iContentId, $aContentInfo) = $mixedContent;
  1840. return $this->_oTemplate->$sFunc($aContentInfo);
  1841. }
  1842. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1843. {
  1844. $sMode = array_shift($aArgs);
  1845. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1846. $this->_oTemplate->displayAccessDenied ($sMsg);
  1847. exit;
  1848. }
  1849. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1850. bx_import ($sClass, $this->_aModule);
  1851. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1852. $o = new $sClass($sMode, $aParams);
  1853. if ($o->isError)
  1854. $this->_oTemplate->displayPageNotFound ();
  1855. else
  1856. $o->outputRSS();
  1857. exit;
  1858. }
  1859. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  1860. {
  1861. if(!$iContentId)
  1862. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1863. if(!$iContentId)
  1864. return false;
  1865. if($sFuncGetContent === true)
  1866. $sFuncGetContent = 'getContentInfoById';
  1867. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1868. return $iContentId;
  1869. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1870. if(!$aContentInfo)
  1871. return false;
  1872. return array($iContentId, $aContentInfo);
  1873. }
  1874. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1875. {
  1876. $CNF = &$this->_oConfig->CNF;
  1877. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1878. //--- Image(s)
  1879. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1880. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1881. //--- Video(s)
  1882. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1883. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1884. //--- Files(s)
  1885. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1886. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1887. //--- Title
  1888. $sTitle = '';
  1889. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1890. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1891. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1892. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1893. //--- Text
  1894. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1895. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1896. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1897. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1898. }
  1899. return array(
  1900. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1901. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1902. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1903. 'url' => $sUrl,
  1904. 'title' => $sTitle,
  1905. 'text' => $sText,
  1906. 'images' => $aImages,
  1907. 'images_attach' => $aImagesAttach,
  1908. 'videos' => $aVideos,
  1909. 'videos_attach' => $aVideosAttach,
  1910. 'files' => $aFiles,
  1911. 'files_attach' => $aFilesAttach
  1912. );
  1913. }
  1914. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1915. {
  1916. $CNF = &$this->_oConfig->CNF;
  1917. $sImage = $sImageOrig = '';
  1918. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1919. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1920. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1921. }
  1922. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1923. if($sImage == '' && $bImageThumb)
  1924. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1925. if($sImageOrig == '' && $bImageThumb)
  1926. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1927. if(empty($sImage))
  1928. return array();
  1929. if($sImageOrig == '')
  1930. $sImageOrig = $sImage;
  1931. return array(
  1932. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1933. );
  1934. }
  1935. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1936. {
  1937. return array();
  1938. }
  1939. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1940. {
  1941. return array();
  1942. }
  1943. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1944. {
  1945. return array();
  1946. }
  1947. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1948. {
  1949. return array();
  1950. }
  1951. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1952. {
  1953. return array();
  1954. }
  1955. protected function _entityComments ($sObject, $iId = 0)
  1956. {
  1957. if (!$iId)
  1958. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1959. if (!$iId)
  1960. return false;
  1961. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1962. if (!$oCmts || !$oCmts->isEnabled())
  1963. return false;
  1964. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1965. }
  1966. protected function _getFields($iContentId)
  1967. {
  1968. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1969. if(empty($aContentInfo))
  1970. return array();
  1971. return BxDolContentInfo::formatFields($aContentInfo);
  1972. }
  1973. protected function _getFieldValue($sField, $iContentId)
  1974. {
  1975. $CNF = &$this->_oConfig->CNF;
  1976. if(empty($CNF[$sField]))
  1977. return false;
  1978. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1979. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1980. return false;
  1981. return $aContentInfo[$CNF[$sField]];
  1982. }
  1983. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1984. {
  1985. $CNF = &$this->_oConfig->CNF;
  1986. if(empty($sTranscoder) || empty($CNF[$sField]))
  1987. return false;
  1988. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1989. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1990. return false;
  1991. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1992. if(!$oImagesTranscoder)
  1993. return false;
  1994. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1995. }
  1996. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1997. {
  1998. if(!$bAsJson)
  1999. return $aResponse;
  2000. if(!empty($aAdditional) && is_array($aAdditional))
  2001. $aResponse = array_merge($aResponse, $aAdditional);
  2002. echoJson($aResponse);
  2003. exit;
  2004. }
  2005. /**
  2006. * Blocks for lables tree browsing private functions
  2007. */
  2008. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2009. {
  2010. $oLabel = BxDolLabel::getInstance();
  2011. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2012. if ($aLabel){
  2013. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2014. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2015. }
  2016. }
  2017. private function _getLablesBrowseUrl($iLabelId)
  2018. {
  2019. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2020. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2021. }
  2022. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2023. {
  2024. $oLabel = BxDolLabel::getInstance();
  2025. $aLabelsOutput = array();
  2026. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2027. if (count($aLabels) > 0){
  2028. foreach($aLabels as $aLabel) {
  2029. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2030. $bChildPresent = $sChild != '' ? true : false;
  2031. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2032. if (!$bIsOpen){
  2033. $sChild = '';
  2034. }
  2035. $aLabelsOutput[] = array(
  2036. 'value' => $aLabel['value'],
  2037. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2038. 'child' => $sChild,
  2039. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2040. 'bx_if:open' => array(
  2041. 'condition' => $bChildPresent && $bIsOpen,
  2042. 'content' => array()
  2043. ),
  2044. 'bx_if:can_open' => array(
  2045. 'condition' => $bChildPresent && !$bIsOpen,
  2046. 'content' => array()
  2047. )
  2048. );
  2049. }
  2050. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2051. array(
  2052. 'bx_repeat:items' => $aLabelsOutput,
  2053. 'parent' => $iParent,
  2054. )
  2055. );
  2056. }
  2057. return '';
  2058. }
  2059. }
  2060. /** @} */