1
0

BxBaseModGeneralModule.php 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132
  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. public function actionGetNotes()
  62. {
  63. $CNF = &$this->_oConfig->CNF;
  64. if(empty($CNF['OBJECT_NOTES']))
  65. return echoJson(array());
  66. $iContentId = (int)bx_get('content_id');
  67. $oCmtsNotes = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], $iContentId, true, $this->_oTemplate);
  68. $aCmtsNotes = $oCmtsNotes->getCommentsBlock(array(), array('in_designbox' => false));
  69. if(empty($aCmtsNotes) || !is_array($aCmtsNotes))
  70. return echoJson(array());
  71. $sPopupId = $this->getName() . '_notes_' . $iContentId;
  72. $sPopupTitle = !empty($CNF['T']['txt_cmts_notes_popup_view_title']) ? $CNF['T']['txt_cmts_notes_popup_view_title'] : '_cmt_nts_popup_view_title';
  73. echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $aCmtsNotes['content'])));
  74. }
  75. public function actionNested()
  76. {
  77. $sAction = bx_get('a');
  78. $sMethodName = 'subaction' . ucfirst($sAction);
  79. if (!method_exists($this, $sMethodName)) {
  80. return;
  81. }
  82. $this->$sMethodName();
  83. }
  84. public function subactionDelete()
  85. {
  86. header('Content-type: text/html; charset=utf-8');
  87. $iNestedId = (int)bx_get('id');
  88. $sNestedForm = bx_get('s');
  89. $oForm = BxDolForm::getObjectInstance($sNestedForm, $sNestedForm);
  90. if (!$oForm){
  91. echo _t('_sys_request_page_not_found_cpt');
  92. return;
  93. }
  94. $aNested = $this->_oDb->getNestedBy(array('type' => 'id', 'id' => $iNestedId, 'key_name' => $oForm->aParams['db']['key']), $oForm->aParams['db']['table']);
  95. if (empty($aNested)){
  96. echo _t('_sys_request_page_not_found_cpt');
  97. return;
  98. }
  99. $aContentInfo = $this->_oDb->getContentInfoById ($aNested['content_id']);
  100. if (!$aContentInfo){
  101. echo _t('_sys_request_page_not_found_cpt');
  102. return;
  103. }
  104. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  105. echo $sMsg;
  106. }
  107. elseif (!$this->_oDb->deleteNestedById($iNestedId, $oForm->aParams['db']['key'], $oForm->aParams['db']['table'])) {
  108. echo _t('_sys_txt_error_occured');
  109. }
  110. else {
  111. echo 'ok';
  112. }
  113. }
  114. // ====== SERVICE METHODS
  115. public function serviceIsBadgesAvaliable()
  116. {
  117. $oBadges = BxDolBadges::getInstance();
  118. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => 0, 'module' => $this->_oConfig->getName()));
  119. return count($aBadges) > 0 ? true : false;
  120. }
  121. public function serviceGetSafeServices()
  122. {
  123. return array(
  124. // other
  125. 'ModuleIcon' => '',
  126. 'GetLink' => '',
  127. // browse
  128. 'GetSearchResultUnit' => '',
  129. 'Browse' => '',
  130. 'BrowseFeatured' => '',
  131. 'BrowseFavorite' => '',
  132. // forms
  133. 'GetCreatePostForm' => '',
  134. 'EntityEdit' => '',
  135. 'EntityDelete' => '',
  136. // page blocks
  137. 'EntityTextBlock' => '',
  138. 'EntityInfo' => '',
  139. 'EntityInfoFull' => '',
  140. 'EntityInfoExtended' => '',
  141. 'EntityLocation' => '',
  142. 'EntityComments' => '',
  143. 'EntityAttachments' => '',
  144. // menu
  145. 'EntityAllActions' => '',
  146. 'EntityActions' => '',
  147. 'EntitySocialSharing' => '',
  148. 'MyEntriesActions' => '',
  149. );
  150. }
  151. /**
  152. * @page service Service Calls
  153. * @section bx_base_general Base General
  154. * @subsection bx_base_general-other Other
  155. * @subsubsection bx_base_general-module_icon module_icon
  156. *
  157. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  158. *
  159. * Get module icon as CSS class name with FontAwesome icon name class and color class
  160. *
  161. * @see BxBaseModGeneralModule::serviceModuleIcon
  162. */
  163. /**
  164. * @ref bx_base_general-module_icon "module_icon"
  165. */
  166. public function serviceModuleIcon ()
  167. {
  168. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  169. }
  170. public function serviceGetAuthor ($iContentId)
  171. {
  172. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  173. return $mixedResult !== false ? (int)$mixedResult : 0;
  174. }
  175. public function serviceGetPrivacyView ($iContentId)
  176. {
  177. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  178. }
  179. public function serviceGetDateAdded ($iContentId)
  180. {
  181. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  182. return $mixedResult !== false ? (int)$mixedResult : 0;
  183. }
  184. public function serviceGetDateChanged ($iContentId)
  185. {
  186. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  187. return $mixedResult !== false ? (int)$mixedResult : 0;
  188. }
  189. /**
  190. * @page service Service Calls
  191. * @section bx_base_general Base General
  192. * @subsection bx_base_general-other Other
  193. * @subsubsection bx_base_general-get_link get_link
  194. *
  195. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  196. *
  197. * Get URL for the specified content.
  198. * @param $iContentId content id
  199. *
  200. * @see BxBaseModGeneralModule::serviceGetLink
  201. */
  202. /**
  203. * @ref bx_base_general-get_link "get_link"
  204. */
  205. public function serviceGetLink ($iContentId)
  206. {
  207. $CNF = &$this->_oConfig->CNF;
  208. if(empty($CNF['URI_VIEW_ENTRY']))
  209. return '';
  210. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  211. if(empty($aContentInfo))
  212. return '';
  213. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  214. }
  215. public function serviceGetTitle ($iContentId)
  216. {
  217. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  218. return $mixedResult !== false ? $mixedResult : '';
  219. }
  220. public function serviceGetText ($iContentId)
  221. {
  222. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  223. if (false === $mixedResult)
  224. return '';
  225. $CNF = &$this->_oConfig->CNF;
  226. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  227. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  228. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  229. }
  230. return $mixedResult;
  231. }
  232. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  233. {
  234. $CNF = &$this->_oConfig->CNF;
  235. $aContentInfo = $this->_getFields($iContentId);
  236. if(empty($aContentInfo))
  237. return array();
  238. if(!$bSearchableFieldsOnly)
  239. return $aContentInfo;
  240. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  241. return array();
  242. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  243. if(empty($aFields))
  244. return array();
  245. $aResult = array();
  246. foreach($aFields as $sField)
  247. if(isset($aContentInfo[$sField]))
  248. $aResult[$sField] = $aContentInfo[$sField];
  249. return $aResult;
  250. }
  251. /**
  252. * @page service Service Calls
  253. * @section bx_base_general Base General
  254. * @subsection bx_base_general-browsing Browsing
  255. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  256. *
  257. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  258. *
  259. * Get browsing unit for the specified content
  260. * @param $iContentId content id
  261. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  262. *
  263. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  264. */
  265. /**
  266. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  267. */
  268. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  269. {
  270. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  271. if(empty($aContentInfo))
  272. return '';
  273. if(empty($sUnitTemplate))
  274. $sUnitTemplate = 'unit.html';
  275. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  276. }
  277. public function serviceGetAll ($aParams = array())
  278. {
  279. if(empty($aParams) || !is_array($aParams))
  280. $aParams = array('type' => 'all');
  281. return $this->_oDb->getEntriesBy($aParams);
  282. }
  283. public function serviceGetAllByAuthor ($iProfileId)
  284. {
  285. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  286. }
  287. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  288. {
  289. $CNF = &$this->_oConfig->CNF;
  290. if(empty($CNF['OBJECT_FORM_ENTRY']))
  291. return array();
  292. $aResult = array();
  293. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  294. $aResult[$CNF['FIELD_AUTHOR']] = array(
  295. 'type' => 'text_auto',
  296. 'caption' => $CNF['T']['form_field_author'],
  297. 'info' => '',
  298. 'value' => '',
  299. 'values' => '',
  300. 'pass' => ''
  301. );
  302. $aInputs = array();
  303. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  304. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  305. $aInputs = array_merge($aInputs, $oForm->aInputs);
  306. }
  307. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  308. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  309. $aInputs = array_merge($aInputs, $oForm->aInputs);
  310. }
  311. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  312. $aInputs = array_merge($aInputs, $aInputsAdd);
  313. foreach($aInputs as $aInput){
  314. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  315. $aField = array(
  316. 'type' => $aInput['type'],
  317. 'caption_system' => $aInput['caption_system_src'],
  318. 'caption' => $aInput['caption_src'],
  319. 'info' => $aInput['info_src'],
  320. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  321. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  322. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  323. );
  324. if(isset($aInput['search_type']))
  325. $aField['search_type'] = $aInput['search_type'];
  326. if(isset($aInput['search_operator']))
  327. $aField['search_operator'] = $aInput['search_operator'];
  328. $aResult[$aInput['name']] = $aField;
  329. }
  330. }
  331. return $aResult;
  332. }
  333. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0, $bFilterMode = false)
  334. {
  335. if((empty($aParams) || !is_array($aParams)) && !$bFilterMode)
  336. return array();
  337. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  338. }
  339. public function serviceGetSearchableFields ($aInputsAdd = array())
  340. {
  341. $CNF = $this->_oConfig->CNF;
  342. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  343. return array();
  344. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  345. if(!$oForm)
  346. return array();
  347. $aInputs = $oForm->aInputs;
  348. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  349. $aInputs = array_merge($aInputs, $aInputsAdd);
  350. $aTextTypes = array('text', 'textarea');
  351. $aTextFields = array();
  352. foreach($aInputs as $r)
  353. if(in_array($r['type'], $aTextTypes))
  354. $aTextFields[$r['name']] = $r['caption'];
  355. return $aTextFields;
  356. }
  357. public function serviceManageTools($sType = 'common')
  358. {
  359. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  360. if(!$oGrid)
  361. return '';
  362. $CNF = &$this->_oConfig->CNF;
  363. $mixedMenu = '';
  364. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  365. $oPermalink = BxDolPermalinks::getInstance();
  366. $aMenuItems = array();
  367. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  368. $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);
  369. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  370. $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);
  371. if(count($aMenuItems) > 1) {
  372. $mixedMenu = new BxTemplMenu(array(
  373. 'template' => 'menu_block_submenu_ver.html',
  374. 'menu_items' => $aMenuItems
  375. ), $this->_oTemplate);
  376. $mixedMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  377. }
  378. }
  379. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  380. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  381. }
  382. $this->_oTemplate->addCss(array('manage_tools.css'));
  383. $this->_oTemplate->addJs(array('manage_tools.js'));
  384. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  385. return array(
  386. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  387. 'menu' => $mixedMenu
  388. );
  389. }
  390. public function serviceGetMenuAddonManageTools()
  391. {
  392. return 0;
  393. }
  394. public function serviceGetMenuAddonManageToolsProfileStats()
  395. {
  396. return 0;
  397. }
  398. /**
  399. * @page service Service Calls
  400. * @section bx_base_general Base General
  401. * @subsection bx_base_general-browsing Browsing
  402. * @subsubsection bx_base_general-browse browse
  403. *
  404. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  405. * @code {{~bx_posts:browse[{"mode":"author", "params":{"author":"10"}}]~}} @endcode
  406. *
  407. * Universal browse method.
  408. * @param $aParams custom browse params, possible params are the following:
  409. * - mode - browse mode, such as 'recent', 'featured', etc
  410. * - params - custom params to browse method, for example 'unit_view' can be passed here
  411. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  412. * - empty_message - display or not "empty" message when there is no content
  413. * - ajax_paginate - use AJAX paginate or not
  414. *
  415. * @see BxBaseModGeneralModule::serviceBrowse
  416. */
  417. /**
  418. * @ref bx_base_general-browse "browse"
  419. */
  420. public function serviceBrowse ($aParams = array())
  421. {
  422. unset($aParams['params']['condition']);
  423. return $this->serviceBrowseWithCondition ($aParams);
  424. }
  425. public function serviceBrowseWithCondition ($aParams = array())
  426. {
  427. $aDefaults = array (
  428. 'mode' => 'recent',
  429. 'params' => false,
  430. 'design_box' => BX_DB_PADDING_DEF,
  431. 'empty_message' => false,
  432. 'ajax_paginate' => true,
  433. 'class_search_result' => 'SearchResult'
  434. );
  435. $aParams = array_merge($aDefaults, $aParams);
  436. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  437. }
  438. /**
  439. * @page service Service Calls
  440. * @section bx_base_general Base General
  441. * @subsection bx_base_general-browsing Browsing
  442. * @subsubsection bx_base_general-browse_featured browse_featured
  443. *
  444. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  445. *
  446. * Display featured entries
  447. * @param $sUnitView browsing unity view,
  448. * such as: full, extended, gallery, showcase
  449. * @param $bEmptyMessage display or not "empty" message when there is no content
  450. * @param $bAjaxPaginate use AJAX paginate or not
  451. *
  452. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  453. */
  454. /**
  455. * @ref bx_base_general-browse_featured "browse_featured"
  456. */
  457. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  458. {
  459. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  460. }
  461. /**
  462. * @page service Service Calls
  463. * @section bx_base_general Base General
  464. * @subsection bx_base_general-browsing Browsing
  465. * @subsubsection bx_base_general-browse_favorite browse_favorite
  466. *
  467. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  468. *
  469. * Display entries which were added to favorite list by some member
  470. * @param $iProfileId profile ID
  471. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  472. *
  473. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  474. */
  475. /**
  476. * @ref bx_base_general-browse_favorite "browse_favorite"
  477. */
  478. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  479. {
  480. $oProfile = null;
  481. if((int)$iProfileId)
  482. $oProfile = BxDolProfile::getInstance($iProfileId);
  483. if(!$oProfile && bx_get('profile_id') !== false)
  484. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  485. if(!$oProfile)
  486. $oProfile = BxDolProfile::getInstance();
  487. if(!$oProfile)
  488. return '';
  489. $bEmptyMessage = true;
  490. if(isset($aParams['empty_message'])) {
  491. $bEmptyMessage = (bool)$aParams['empty_message'];
  492. unset($aParams['empty_message']);
  493. }
  494. if(bx_get('list_id') !== false && !isset($aParams['list_id']))
  495. $aParams['list_id'] = (int) bx_get('list_id');
  496. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  497. }
  498. /**
  499. * @page service Service Calls
  500. * @section bx_base_general Base General
  501. * @subsection bx_base_general-browsing Browsing
  502. * @subsubsection bx_base_general-browse_favorite_lists browse_favorite_lists
  503. *
  504. * @code bx_srv('bx_posts', 'browse_favorite_lists', [...]); @endcode
  505. *
  506. * Display entries which were added to favorite lists grouped by lists by some member
  507. * @param $iProfileId profile ID
  508. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  509. *
  510. * @see BxBaseModGeneralModule::serviceBrowseFavoriteLists BxBaseModGeneralModule::serviceBrowse
  511. */
  512. /**
  513. * @ref bx_base_general-browse_favorite_lists "browse_favorite_lists"
  514. */
  515. public function serviceBrowseFavoriteLists ($iProfileId = 0, $aParams = array())
  516. {
  517. $CNF = &$this->_oConfig->CNF;
  518. $oProfile = null;
  519. if((int)$iProfileId)
  520. $oProfile = BxDolProfile::getInstance($iProfileId);
  521. if(!$oProfile && bx_get('profile_id') !== false)
  522. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  523. if(!$oProfile)
  524. $oProfile = BxDolProfile::getInstance();
  525. if(!$oProfile)
  526. return '';
  527. $iStart = (bx_get('list_start') !== false ? (int)bx_get('list_start') : 0);
  528. $iPerPage = (int)getParam($CNF['PARAM_PER_PAGE_FOR_FAVORITES_LISTS']);
  529. return $this->_oTemplate->getFavoriteList($oProfile, $iStart, $iPerPage, $aParams);
  530. }
  531. /**
  532. * @page service Service Calls
  533. * @section bx_base_general Base General
  534. * @subsection bx_base_general-browsing Browsing
  535. * @subsubsection bx_base_general-browse_favorite_list_actions browse_favorite_list_actions
  536. *
  537. * @code bx_srv('bx_posts', 'browse_favorite_list_actions', [...]); @endcode
  538. *
  539. * Display menu actions for favorite lists
  540. *
  541. * @see BxBaseModGeneralModule::serviceFavoritesListActions
  542. */
  543. /**
  544. * @ref bx_base_general-browse_favorite_list_actions "browse_favorite_list_actions"
  545. */
  546. public function serviceFavoritesListActions()
  547. {
  548. $iListId = 0;
  549. if(bx_get('list_id') !== false)
  550. $iListId = (int) bx_get('list_id');
  551. $oProfile = null;
  552. if(bx_get('profile_id') !== false)
  553. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  554. if(!$oProfile)
  555. return false;
  556. $CNF = &$this->_oConfig->CNF;
  557. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  558. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  559. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  560. return false;
  561. $sRv = '';
  562. if (!empty($aList) && $oFavorite->isAllowedEditList($aList['author_id'])){
  563. $aMarkers = array(
  564. 'js_object' => $oFavorite->getJsObjectName(),
  565. 'list_id' => $iListId,
  566. );
  567. $oMenu = BxDolMenu::getObjectInstance('sys_favorite_list');
  568. $oMenu->addMarkers($aMarkers);
  569. $sMenu = $oMenu->getCode();
  570. $sRv .= $sMenu . $oFavorite->getJsScript();
  571. }
  572. $aMarkers = array(
  573. 'id' => $iListId,
  574. 'module' => $this->_aModule['name'],
  575. 'url' => $this->_getFavoriteListUrl($iListId, $oProfile->id()),
  576. 'title' => $iListId > 0 ? $aList['title'] : _t('_sys_txt_default_favorite_list')
  577. );
  578. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  579. $oMenu->addMarkers($aMarkers);
  580. $sRv .= $sMenu = $oMenu->getCode();
  581. return $sRv;
  582. }
  583. /**
  584. * @page service Service Calls
  585. * @section bx_base_general Base General
  586. * @subsection bx_base_general-menu Menu
  587. * @subsubsection bx_base_general-favorites_list_info favorites_list_info
  588. *
  589. * @code bx_srv('bx_posts', 'favorites_list_info', [...]); @endcode
  590. *
  591. * Favorites list info
  592. * @param $aParams array with additional custom params
  593. * which may overwrite some default values
  594. *
  595. * @see BxBaseModGeneralModule::serviceFavoritesListInfo
  596. */
  597. /**
  598. * @ref bx_base_general-favorites_list_info "favorites_list_info"
  599. */
  600. public function serviceFavoritesListInfo($aParams = array())
  601. {
  602. $CNF = &$this->_oConfig->CNF;
  603. $iListId = 0;
  604. if(bx_get('list_id') !== false)
  605. $iListId = (int) bx_get('list_id');
  606. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  607. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  608. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  609. return false;
  610. $oProfile = null;
  611. if(bx_get('profile_id') !== false)
  612. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  613. if(!$oProfile)
  614. return false;
  615. return $this->_oTemplate->getFavoritesListInfo($aList, $oProfile);
  616. }
  617. /**
  618. * Display entries posted into particular context
  619. * @return HTML string
  620. */
  621. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  622. {
  623. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  624. }
  625. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  626. {
  627. if(!$sParamVal)
  628. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  629. if(!$sParamVal)
  630. return '';
  631. $bEmptyMessage = true;
  632. if(isset($aParams['empty_message'])) {
  633. $bEmptyMessage = (bool)$aParams['empty_message'];
  634. unset($aParams['empty_message']);
  635. }
  636. $bAjaxPaginate = true;
  637. if(isset($aParams['ajax_paginate'])) {
  638. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  639. unset($aParams['ajax_paginate']);
  640. }
  641. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  642. }
  643. public function serviceFormsHelper ()
  644. {
  645. bx_import('FormsEntryHelper', $this->_aModule);
  646. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  647. return new $sClass($this);
  648. }
  649. /**
  650. * Add entry using provided fields' values.
  651. * @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
  652. */
  653. public function serviceEntityAdd ($iProfile, $aValues, $sDisplay = false)
  654. {
  655. bx_import('FormsEntryHelper', $this->_aModule);
  656. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  657. $oFormsHelper = new $sClass($this);
  658. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  659. }
  660. /**
  661. * Perform redirect after content creation
  662. * @return nothing, rediret header is sent
  663. */
  664. public function serviceRedirectAfterAdd($aContentInfo)
  665. {
  666. bx_import('FormsEntryHelper', $this->_aModule);
  667. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  668. $oFormsHelper = new $sClass($this);
  669. $oFormsHelper->redirectAfterAdd($aContentInfo);
  670. }
  671. /**
  672. * Get form object for add, edit, view or delete the content
  673. * @param $sType 'add', 'edit', 'view' or 'delete'
  674. * @param $aParams optional array with parameters(display name, etc)
  675. * @return form object or false on error
  676. */
  677. public function serviceGetObjectForm ($sType, $aParams = array())
  678. {
  679. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  680. return false;
  681. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  682. $bContext = $mixedContextId !== false;
  683. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  684. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  685. return false;
  686. $CNF = &$this->_oConfig->CNF;
  687. bx_import('FormsEntryHelper', $this->_aModule);
  688. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  689. $oFormsHelper = new $sClass($this);
  690. $sParamsKey = 'ajax_mode';
  691. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  692. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  693. $sParamsKey = 'absolute_action_url';
  694. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  695. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  696. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  697. $sFunc = 'getObjectForm' . ucfirst($sType);
  698. $oForm = $oFormsHelper->$sFunc($sDisplay);
  699. $sKey = 'FIELD_ALLOW_VIEW_TO';
  700. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  701. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  702. if(!$bContext || $bContextOwner) {
  703. $iGc = 0;
  704. $iKeyGh = false;
  705. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  706. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  707. if($iKeyGh !== false && $iGc == 0) {
  708. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  709. $iKeyGh = false;
  710. if($aValue['type'] == 'group_end')
  711. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  712. }
  713. if($aValue['type'] == 'group_header') {
  714. $iGc = 0;
  715. $iKeyGh = $iKey;
  716. }
  717. continue;
  718. }
  719. //--- Show 'Public' privacy group only in Public post form.
  720. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  721. $iGc += 1;
  722. continue;
  723. }
  724. //--- Show a default privacy groups in Profile (for Owner) post form.
  725. if($bContextOwner && ((int)$aValue['key'] >= 0 || $mixedContextId == $aValue['key'])) {
  726. $iGc += 1;
  727. continue;
  728. }
  729. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  730. }
  731. }
  732. else {
  733. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  734. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  735. }
  736. }
  737. bx_alert('system', 'get_object_form', 0, 0, array(
  738. 'module' => $this->_oConfig->getName(),
  739. 'type' => $sType,
  740. 'params' => $aParams,
  741. 'form' => &$oForm
  742. ));
  743. return $oForm;
  744. }
  745. /**
  746. *
  747. *
  748. * Create entry form
  749. * @return HTML string
  750. */
  751. public function serviceEntityCreate ($sParams = false)
  752. {
  753. $bParamsArray = is_array($sParams);
  754. $sDisplay = is_string($sParams) ? $sParams : false;
  755. if($bParamsArray && !empty($sParams['display']))
  756. $sDisplay = $sParams['display'];
  757. bx_import('FormsEntryHelper', $this->_aModule);
  758. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  759. $oFormsHelper = new $sClass($this);
  760. if($bParamsArray && isset($sParams['dynamic_mode']))
  761. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  762. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  763. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  764. echoJson($mixedResult);
  765. exit;
  766. }
  767. return $mixedResult;
  768. }
  769. /**
  770. * @page service Service Calls
  771. * @section bx_base_general Base General
  772. * @subsection bx_base_general-forms Forms
  773. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  774. *
  775. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  776. *
  777. * Get content creation form
  778. * @param $aParams additional parameters array:
  779. * context_id, ajax_mode, absolute_action_url, displays
  780. *
  781. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  782. */
  783. /**
  784. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  785. */
  786. public function serviceGetCreatePostForm($aParams = array())
  787. {
  788. $aParams = array_merge($this->_aFormParams, $aParams);
  789. $oForm = $this->serviceGetObjectForm('add', $aParams);
  790. if(!$oForm)
  791. return '';
  792. return $this->serviceEntityCreate($aParams);
  793. }
  794. /**
  795. * @page service Service Calls
  796. * @section bx_base_general Base General
  797. * @subsection bx_base_general-forms Forms
  798. * @subsubsection bx_base_general-entity_edit entity_edit
  799. *
  800. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  801. *
  802. * Get content edit form
  803. * @param $iContentId content ID
  804. * @param $sDisplay optional form display name
  805. *
  806. * @see BxBaseModGeneralModule::serviceEntityEdit
  807. */
  808. /**
  809. * @ref bx_base_general-entity_edit "entity_edit"
  810. */
  811. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  812. {
  813. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  814. }
  815. /**
  816. * @page service Service Calls
  817. * @section bx_base_general Base General
  818. * @subsection bx_base_general-forms Forms
  819. * @subsubsection bx_base_general-entity_delete entity_delete
  820. *
  821. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  822. *
  823. * Get content delete form
  824. * @param $iContentId content ID
  825. *
  826. * @see BxBaseModGeneralModule::serviceEntityDelete
  827. */
  828. /**
  829. * @ref bx_base_general-entity_delete "entity_delete"
  830. */
  831. public function serviceEntityDelete ($iContentId = 0)
  832. {
  833. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  834. }
  835. /**
  836. * @page service Service Calls
  837. * @section bx_base_general Base General
  838. * @subsection bx_base_general-page_blocks Page Blocks
  839. * @subsubsection bx_base_general-entity_text_block entity_text_block
  840. *
  841. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  842. *
  843. * Get content text/description
  844. * @param $iContentId content ID
  845. *
  846. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  847. */
  848. /**
  849. * @ref bx_base_general-entity_text_block "entity_text_block"
  850. */
  851. public function serviceEntityTextBlock ($iContentId = 0)
  852. {
  853. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  854. }
  855. /**
  856. * @page service Service Calls
  857. * @section bx_base_general Base General
  858. * @subsection bx_base_general-page_blocks Page Blocks
  859. * @subsubsection bx_base_general-entity_info entity_info
  860. *
  861. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  862. *
  863. * Get content info
  864. * @param $iContentId content ID
  865. *
  866. * @see BxBaseModGeneralModule::serviceEntityInfo
  867. */
  868. /**
  869. * @ref bx_base_general-entity_info "entity_info"
  870. */
  871. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  872. {
  873. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  874. }
  875. /**
  876. * @page service Service Calls
  877. * @section bx_base_general Base General
  878. * @subsection bx_base_general-page_blocks Page Blocks
  879. * @subsubsection bx_base_general-entity_info_full entity_info_full
  880. *
  881. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  882. *
  883. * Get full content info
  884. * @param $iContentId content ID
  885. *
  886. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  887. */
  888. /**
  889. * @ref bx_base_general-entity_info_full "entity_info_full"
  890. */
  891. public function serviceEntityInfoFull ($iContentId = 0)
  892. {
  893. $CNF = &$this->_oConfig->CNF;
  894. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  895. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  896. }
  897. /**
  898. * @page service Service Calls
  899. * @section bx_base_general Base General
  900. * @subsection bx_base_general-page_blocks Page Blocks
  901. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  902. *
  903. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  904. *
  905. * Get extended content info
  906. * @param $iContentId content ID
  907. *
  908. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  909. */
  910. /**
  911. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  912. */
  913. public function serviceEntityInfoExtended ($iContentId = 0)
  914. {
  915. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  916. }
  917. /**
  918. * @page service Service Calls
  919. * @section bx_base_general Base General
  920. * @subsection bx_base_general-page_blocks Page Blocks
  921. * @subsubsection bx_base_general-entity_location entity_location
  922. *
  923. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  924. *
  925. * Get content location
  926. * @param $iContentId content ID
  927. *
  928. * @see BxBaseModGeneralModule::serviceEntityLocation
  929. */
  930. /**
  931. * @ref bx_base_general-entity_location "entity_location"
  932. */
  933. public function serviceEntityLocation ($iContentId = 0)
  934. {
  935. $iContentId = $this->_getContent($iContentId, false);
  936. if($iContentId === false)
  937. return false;
  938. return $this->_oTemplate->entryLocation ($iContentId);
  939. }
  940. /**
  941. * @page service Service Calls
  942. * @section bx_base_general Base General
  943. * @subsection bx_base_general-page_blocks Page Blocks
  944. * @subsubsection bx_base_general-entity_comments entity_comments
  945. *
  946. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  947. *
  948. * Get content comments
  949. * @param $iContentId content ID
  950. *
  951. * @see BxBaseModGeneralModule::serviceEntityComments
  952. */
  953. /**
  954. * @ref bx_base_general-entity_comments "entity_comments"
  955. */
  956. public function serviceEntityComments ($iContentId = 0)
  957. {
  958. $CNF = &$this->_oConfig->CNF;
  959. if(empty($CNF['OBJECT_COMMENTS']))
  960. return '';
  961. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  962. }
  963. /**
  964. * @page service Service Calls
  965. * @section bx_base_general Base General
  966. * @subsection bx_base_general-page_blocks Page Blocks
  967. * @subsubsection bx_base_general-entity_attachments entity_attachments
  968. *
  969. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  970. *
  971. * Get content attachments
  972. * @param $iContentId content ID
  973. *
  974. * @see BxBaseModGeneralModule::serviceEntityAttachments
  975. */
  976. /**
  977. * @ref bx_base_general-entity_attachments "entity_attachments"
  978. */
  979. public function serviceEntityAttachments ($iContentId = 0)
  980. {
  981. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  982. }
  983. /**
  984. * Delete content entry
  985. * @param $iContentId content id
  986. * @return error message or empty string on success
  987. */
  988. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  989. {
  990. bx_import('FormsEntryHelper', $this->_aModule);
  991. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  992. $oFormsHelper = new $sClass($this);
  993. return $oFormsHelper->$sFuncDelete($iContentId);
  994. }
  995. /**
  996. * @page service Service Calls
  997. * @section bx_base_general Base General
  998. * @subsection bx_base_general-menu Menu
  999. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1000. *
  1001. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1002. *
  1003. * My entries actions menu
  1004. * @param $iProfileId profiles ID,
  1005. * if omitted it try to get it from 'profile_id' GET param
  1006. *
  1007. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1008. */
  1009. /**
  1010. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1011. */
  1012. public function serviceMyEntriesActions ($iProfileId = 0)
  1013. {
  1014. $CNF = &$this->_oConfig->CNF;
  1015. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1016. return false;
  1017. if (!$iProfileId)
  1018. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1019. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1020. return false;
  1021. if ($iProfileId != $this->_iProfileId)
  1022. return false;
  1023. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1024. return $oMenu ? $oMenu->getCode() : false;
  1025. }
  1026. /**
  1027. * @page service Service Calls
  1028. * @section bx_base_general Base General
  1029. * @subsection bx_base_general-menu Menu
  1030. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  1031. *
  1032. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  1033. *
  1034. * Entry actions and social sharing actions
  1035. * @param $mixedContent content ID
  1036. * @param $aParams additional params
  1037. *
  1038. * @see BxBaseModGeneralModule::serviceEntityAllActions
  1039. */
  1040. /**
  1041. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  1042. */
  1043. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  1044. {
  1045. $CNF = &$this->_oConfig->CNF;
  1046. if(!empty($mixedContent)) {
  1047. if(!is_array($mixedContent))
  1048. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  1049. }
  1050. else {
  1051. $mixedContent = $this->_getContent();
  1052. if($mixedContent === false)
  1053. return false;
  1054. }
  1055. list($iContentId, $aContentInfo) = $mixedContent;
  1056. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  1057. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  1058. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  1059. if(empty($sObjectMenu))
  1060. return false;
  1061. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  1062. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1063. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1064. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  1065. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  1066. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  1067. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  1068. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1069. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1070. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  1071. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  1072. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  1073. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  1074. $aMarkers = array(
  1075. 'id' => $iContentId,
  1076. 'module' => $this->_oConfig->getName(),
  1077. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  1078. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  1079. 'img_url' => ''
  1080. );
  1081. if(!empty($iEntryThumb)) {
  1082. if(!empty($sObjectTranscoder))
  1083. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  1084. else if(!empty($sObjectStorage))
  1085. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  1086. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  1087. if(!empty($sImageUrl))
  1088. $aMarkers['img_url'] = $sImageUrl;
  1089. }
  1090. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  1091. if(!$oActions)
  1092. return false;
  1093. $oActions->setContentId($iContentId);
  1094. $oActions->addMarkers($aMarkers);
  1095. return $this->_oTemplate->entryAllActions($oActions->getCode());
  1096. }
  1097. /**
  1098. * @page service Service Calls
  1099. * @section bx_base_general Base General
  1100. * @subsection bx_base_general-menu Menu
  1101. * @subsubsection bx_base_general-entity_actions entity_actions
  1102. *
  1103. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  1104. *
  1105. * Entry actions, without social sharing actions
  1106. * @param $iContentId content ID
  1107. *
  1108. * @see BxBaseModGeneralModule::serviceEntityActions
  1109. */
  1110. /**
  1111. * @ref bx_base_general-entity_actions "entity_actions"
  1112. */
  1113. public function serviceEntityActions ($iContentId = 0)
  1114. {
  1115. $iContentId = $this->_getContent($iContentId, false);
  1116. if($iContentId === false)
  1117. return false;
  1118. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  1119. return $oMenu ? $oMenu->getCode() : false;
  1120. }
  1121. /**
  1122. * @page service Service Calls
  1123. * @section bx_base_general Base General
  1124. * @subsection bx_base_general-page_blocks Page Blocks
  1125. * @subsubsection bx_base_general-entity_reports entity_reports
  1126. *
  1127. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  1128. *
  1129. * Get content reports
  1130. * @param $iContentId content ID
  1131. *
  1132. * @see BxBaseModGeneralModule::serviceEntityReports
  1133. */
  1134. /**
  1135. * @ref bx_base_general-entity_reports "entity_reports"
  1136. */
  1137. public function serviceEntityReports ($iContentId = 0)
  1138. {
  1139. $mixedContent = $this->_getContent($iContentId);
  1140. list($iContentId, $aContentInfo) = $mixedContent;
  1141. if($iContentId === false)
  1142. return false;
  1143. $CNF = &$this->_oConfig->CNF;
  1144. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1145. return false;
  1146. if(!(BxDolAcl::getInstance()->isMemberLevelInSet(192) || bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']]))
  1147. return false;
  1148. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  1149. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  1150. }
  1151. /**
  1152. * @page service Service Calls
  1153. * @section bx_base_general Base General
  1154. * @subsection bx_base_general-page_blocks Page Blocks
  1155. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1156. *
  1157. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1158. *
  1159. * Get number of reports with specified status
  1160. * @param $iStatus status ID
  1161. *
  1162. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  1163. */
  1164. /**
  1165. * @ref bx_base_general-entity_reports "entity_reports"
  1166. */
  1167. public function serviceReportsCountByStatus ($iStatus)
  1168. {
  1169. $CNF = &$this->_oConfig->CNF;
  1170. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1171. return false;
  1172. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  1173. return $oReport->getCountByStatus($iStatus);
  1174. }
  1175. /**
  1176. * @page service Service Calls
  1177. * @section bx_base_general Base General
  1178. * @subsection bx_base_general-menu Menu
  1179. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  1180. *
  1181. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  1182. *
  1183. * Entry social sharing actions
  1184. * @param $mixedContent content ID or array with integer content ID and
  1185. * array with content info, or false
  1186. * @param $aParams array with additional custom params
  1187. * which may overwrite some default values
  1188. *
  1189. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  1190. */
  1191. /**
  1192. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  1193. */
  1194. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  1195. {
  1196. if(!empty($mixedContent)) {
  1197. if(!is_array($mixedContent))
  1198. $mixedContent = array((int)$mixedContent, array());
  1199. }
  1200. else {
  1201. $mixedContent = $this->_getContent();
  1202. if($mixedContent === false)
  1203. return false;
  1204. }
  1205. list($iContentId, $aContentInfo) = $mixedContent;
  1206. $CNF = &$this->_oConfig->CNF;
  1207. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  1208. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  1209. $sUri = $CNF['URI_VIEW_ENTRY'];
  1210. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  1211. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  1212. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1213. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1214. $aMarkers = array(
  1215. 'id' => $iContentId,
  1216. 'module' => $this->_aModule['name'],
  1217. 'url' => BX_DOL_URL_ROOT . $sUrl,
  1218. 'title' => $sTitle,
  1219. );
  1220. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1221. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1222. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1223. if ($iIdThumb) {
  1224. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  1225. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  1226. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  1227. $sStorage = $CNF['OBJECT_STORAGE'];
  1228. if(!empty($sTranscoder))
  1229. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  1230. else if(!empty($sStorage))
  1231. $o = BxDolStorage::getObjectInstance($sStorage);
  1232. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1233. if($sImgUrl)
  1234. $aMarkers['img_url'] = $sImgUrl;
  1235. }
  1236. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1237. $oMenu->addMarkers($aMarkers);
  1238. $sMenu = $oMenu->getCode();
  1239. if(empty($sMenu))
  1240. return '';
  1241. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1242. 'menu' => $sMenu
  1243. ));
  1244. }
  1245. /**
  1246. * Entry context block
  1247. */
  1248. public function serviceEntityContext ($iContentId = 0)
  1249. {
  1250. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1251. }
  1252. /**
  1253. * Blocks for lables tree browsing
  1254. */
  1255. public function serviceGetLablesTree()
  1256. {
  1257. $aBreadcrumbs = array();
  1258. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1259. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1260. }
  1261. public function serviceGetLablesBreadcrumbs()
  1262. {
  1263. if (bx_get('label')){
  1264. $aBreadcrumbs = array();
  1265. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1266. $aLabels = array();
  1267. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1268. $aLabels[] = array(
  1269. 'value' => $aLabel['value'],
  1270. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1271. );
  1272. }
  1273. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1274. }
  1275. return '';
  1276. }
  1277. public function serviceBrowseByLabel()
  1278. {
  1279. $CNF = &$this->_oConfig->CNF;
  1280. if (empty($CNF['OBJECT_METATAGS']))
  1281. return '';
  1282. $sMode = 'recent';
  1283. $sClassSearchResult ='SearchResult';
  1284. bx_import($sClassSearchResult, $this->_aModule['name']);
  1285. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1286. $o = new $sClass($sMode, false);
  1287. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1288. $o->setDisplayEmptyMsg(true);
  1289. $o->setAjaxPaginate(false);
  1290. $o->setUnitParams(array('context' => $sMode));
  1291. if (bx_get('label')){
  1292. $iLabelId = (int)bx_get('label');
  1293. $oLabel = BxDolLabel::getInstance();
  1294. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1295. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1296. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1297. }
  1298. if ($o->isError)
  1299. return '';
  1300. if ($s = $o->processing())
  1301. return $s;
  1302. else
  1303. return '';
  1304. }
  1305. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  1306. {
  1307. $CNF = &$this->_oConfig->CNF;
  1308. $sClassSearchResult ='SearchResult';
  1309. bx_import($sClassSearchResult, $this->_aModule['name']);
  1310. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1311. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  1312. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1313. $o->setAjaxPaginate($bAjaxPaginate);
  1314. $o->setCategoryObject('multi');
  1315. $aCategoriesOutput = array();
  1316. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  1317. foreach($aCategories as $aCategory){
  1318. if ($aCategory['num'] > 0){
  1319. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  1320. $o->setPaginatePerPage(2);
  1321. if (!$o->isError){
  1322. $aResult = $o->processing();
  1323. if ($aResult && $aResult['content'] != '')
  1324. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  1325. }
  1326. }
  1327. }
  1328. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  1329. 'bx_repeat:categories' => $aCategoriesOutput,
  1330. ));
  1331. }
  1332. /**
  1333. * Data for Notifications module
  1334. */
  1335. public function serviceGetNotificationsData()
  1336. {
  1337. $sModule = $this->_aModule['name'];
  1338. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1339. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1340. $sEventPrivacy = '';
  1341. $aResult = array(
  1342. 'handlers' => array(
  1343. 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),
  1344. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1345. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  1346. 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),
  1347. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1348. 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),
  1349. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1350. 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),
  1351. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1352. 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),
  1353. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1354. 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),
  1355. 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),
  1356. ),
  1357. 'settings' => array(
  1358. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  1359. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1360. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1361. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1362. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1363. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1364. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1365. ),
  1366. 'alerts' => array(
  1367. array('unit' => $sModule, 'action' => 'added'),
  1368. array('unit' => $sModule, 'action' => 'edited'),
  1369. array('unit' => $sModule, 'action' => 'deleted'),
  1370. array('unit' => $sModule, 'action' => 'commentPost'),
  1371. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1372. array('unit' => $sModule, 'action' => 'replyPost'),
  1373. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1374. array('unit' => $sModule, 'action' => 'doVote'),
  1375. array('unit' => $sModule, 'action' => 'undoVote'),
  1376. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1377. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1378. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1379. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1380. )
  1381. );
  1382. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1383. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  1384. 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' => ''),
  1385. 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' => ''),
  1386. ));
  1387. $aResult['settings'] = array_merge($aResult['settings'], array(
  1388. array('group' => 'content_publish_failed', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1389. array('group' => 'content_publish_succeeded', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1390. ));
  1391. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  1392. array('unit' => $sModule, 'action' => 'publish_failed'),
  1393. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1394. ));
  1395. }
  1396. return $aResult;
  1397. }
  1398. /**
  1399. * Entry post for Notifications module
  1400. */
  1401. public function serviceGetNotificationsPost($aEvent)
  1402. {
  1403. $CNF = &$this->_oConfig->CNF;
  1404. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1405. if(empty($aContentInfo) || !is_array($aContentInfo))
  1406. return array();
  1407. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1408. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1409. return array(
  1410. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1411. 'entry_url' => $sEntryUrl,
  1412. 'entry_caption' => $sEntryCaption,
  1413. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1414. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1415. 'lang_key' => '', //may be empty or not specified, or a string, or an array('site' => '...', 'email' => '...', 'push' => '...'). In this case of empty/not specified the default one from Notification module will be used.
  1416. /*
  1417. * Custom settings for email and/or push notifications can be provided here.
  1418. * Only necessary parts of 'settings' array can be used.
  1419. *
  1420. 'settings' => array(
  1421. 'email' => array(
  1422. 'template' => '', //--- custom email template
  1423. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1424. 'subject' => '' //--- custom email subject
  1425. ),
  1426. 'push' => array(
  1427. 'subject' => '' //--- custom push notification subject
  1428. )
  1429. )
  1430. */
  1431. );
  1432. }
  1433. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1434. {
  1435. return $this->serviceGetNotificationsPost($aEvent);
  1436. }
  1437. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1438. {
  1439. return $this->serviceGetNotificationsPost($aEvent);
  1440. }
  1441. /**
  1442. * Entry post comment for Notifications module
  1443. */
  1444. public function serviceGetNotificationsComment($aEvent)
  1445. {
  1446. $CNF = &$this->_oConfig->CNF;
  1447. $iContentId = (int)$aEvent['object_id'];
  1448. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1449. if(empty($aContentInfo) || !is_array($aContentInfo))
  1450. return array();
  1451. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1452. if(!$oComment || !$oComment->isEnabled())
  1453. return array();
  1454. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1455. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1456. return array(
  1457. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1458. 'entry_url' => $sEntryUrl,
  1459. 'entry_caption' => $sEntryCaption,
  1460. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1461. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1462. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1463. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1464. );
  1465. }
  1466. /**
  1467. * Entry post reply for Notifications module
  1468. */
  1469. public function serviceGetNotificationsReply($aEvent)
  1470. {
  1471. $CNF = &$this->_oConfig->CNF;
  1472. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1473. if(!$oComment || !$oComment->isEnabled())
  1474. return array();
  1475. $iParentId = (int)$aEvent['object_id'];
  1476. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1477. if(empty($aParentInfo) || !is_array($aParentInfo))
  1478. return array();
  1479. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1480. $oComment->init($iObjectId);
  1481. return array(
  1482. 'object_id' => $iObjectId,
  1483. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1484. 'entry_url' => $oComment->getViewUrl($iParentId),
  1485. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1486. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1487. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1488. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1489. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1490. );
  1491. }
  1492. /**
  1493. * Entry post vote for Notifications module
  1494. */
  1495. public function serviceGetNotificationsVote($aEvent)
  1496. {
  1497. $CNF = &$this->_oConfig->CNF;
  1498. $iContentId = (int)$aEvent['object_id'];
  1499. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1500. if(empty($aContentInfo) || !is_array($aContentInfo))
  1501. return array();
  1502. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1503. if(!$oVote || !$oVote->isEnabled())
  1504. return array();
  1505. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1506. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1507. return array(
  1508. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1509. 'entry_url' => $sEntryUrl,
  1510. 'entry_caption' => $sEntryCaption,
  1511. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1512. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1513. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1514. );
  1515. }
  1516. /**
  1517. * Entry post vote for Notifications module
  1518. */
  1519. public function serviceGetNotificationsReaction($aEvent)
  1520. {
  1521. $CNF = &$this->_oConfig->CNF;
  1522. $iContentId = (int)$aEvent['object_id'];
  1523. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1524. if(empty($aContentInfo) || !is_array($aContentInfo))
  1525. return array();
  1526. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1527. if(!$oReaction || !$oReaction->isEnabled())
  1528. return array();
  1529. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1530. if(empty($aSubentry) || !is_array($aSubentry))
  1531. return array();
  1532. $aSubentrySampleParams = array();
  1533. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1534. if(!empty($aReaction['title']))
  1535. $aSubentrySampleParams[] = $aReaction['title'];
  1536. else
  1537. $aSubentrySampleParams[] = '_undefined';
  1538. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1539. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1540. return array(
  1541. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1542. 'entry_url' => $sEntryUrl,
  1543. 'entry_caption' => $sEntryCaption,
  1544. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1545. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1546. 'subentry_sample_params' => $aSubentrySampleParams,
  1547. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1548. );
  1549. }
  1550. /**
  1551. * Entry post score -> vote up for Notifications module
  1552. */
  1553. public function serviceGetNotificationsScoreUp($aEvent)
  1554. {
  1555. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1556. }
  1557. /**
  1558. * Entry post score -> vote up for Notifications module
  1559. */
  1560. public function serviceGetNotificationsScoreDown($aEvent)
  1561. {
  1562. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1563. }
  1564. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1565. {
  1566. $CNF = &$this->_oConfig->CNF;
  1567. $iContentId = (int)$aEvent['object_id'];
  1568. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1569. if(empty($aContentInfo) || !is_array($aContentInfo))
  1570. return array();
  1571. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1572. if(!$oScore || !$oScore->isEnabled())
  1573. return array();
  1574. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1575. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1576. return array(
  1577. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1578. 'entry_url' => $sEntryUrl,
  1579. 'entry_caption' => $sEntryCaption,
  1580. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1581. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1582. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1583. );
  1584. }
  1585. /**
  1586. * Data for Timeline module
  1587. */
  1588. public function serviceGetTimelineData()
  1589. {
  1590. $sModule = $this->_aModule['name'];
  1591. return array(
  1592. 'handlers' => array(
  1593. 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' => ''),
  1594. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1595. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1596. ),
  1597. 'alerts' => array(
  1598. array('unit' => $sModule, 'action' => 'added'),
  1599. array('unit' => $sModule, 'action' => 'edited'),
  1600. array('unit' => $sModule, 'action' => 'deleted'),
  1601. )
  1602. );
  1603. }
  1604. /**
  1605. * Entry post for Timeline module
  1606. */
  1607. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1608. {
  1609. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1610. if(empty($aContentInfo) || !is_array($aContentInfo))
  1611. return false;
  1612. $CNF = &$this->_oConfig->CNF;
  1613. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1614. return false;
  1615. $iUserId = $this->getUserId();
  1616. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1617. $iAuthorIdAbs = abs($iAuthorId);
  1618. 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)
  1619. return false;
  1620. //--- Views
  1621. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1622. $aViews = array();
  1623. if ($oViews && $oViews->isEnabled())
  1624. $aViews = array(
  1625. 'system' => $CNF['OBJECT_VIEWS'],
  1626. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1627. 'count' => $aContentInfo['views']
  1628. );
  1629. //--- Votes
  1630. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1631. $aVotes = array();
  1632. if ($oVotes && $oVotes->isEnabled())
  1633. $aVotes = array(
  1634. 'system' => $CNF['OBJECT_VOTES'],
  1635. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1636. 'count' => $aContentInfo['votes']
  1637. );
  1638. //--- Reactions
  1639. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1640. $aReactions = array();
  1641. if ($oReactions && $oReactions->isEnabled())
  1642. $aReactions = array(
  1643. 'system' => $CNF['OBJECT_REACTIONS'],
  1644. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1645. 'count' => $aContentInfo['rvotes']
  1646. );
  1647. //--- Scores
  1648. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1649. $aScores = array();
  1650. if ($oScores && $oScores->isEnabled())
  1651. $aScores = array(
  1652. 'system' => $CNF['OBJECT_SCORES'],
  1653. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1654. 'score' => $aContentInfo['score']
  1655. );
  1656. //--- Reports
  1657. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1658. $aReports = array();
  1659. if ($oReports && $oReports->isEnabled())
  1660. $aReports = array(
  1661. 'system' => $CNF['OBJECT_REPORTS'],
  1662. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1663. 'count' => $aContentInfo['reports']
  1664. );
  1665. //--- Comments
  1666. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1667. $aComments = array();
  1668. if($oCmts && $oCmts->isEnabled())
  1669. $aComments = array(
  1670. 'system' => $CNF['OBJECT_COMMENTS'],
  1671. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1672. 'count' => $aContentInfo['comments']
  1673. );
  1674. //--- Title & Description
  1675. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1676. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1677. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1678. $iOwnerId = $iAuthorIdAbs;
  1679. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1680. $iOwnerId = abs($aEvent['object_privacy_view']);
  1681. $bCache = true;
  1682. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1683. if(isset($aContent['_cache'])) {
  1684. $bCache = (bool)$aContent['_cache'];
  1685. unset($aContent['_cache']);
  1686. }
  1687. return array(
  1688. '_cache' => $bCache,
  1689. 'owner_id' => $iOwnerId,
  1690. 'object_owner_id' => $iAuthorId,
  1691. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1692. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1693. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1694. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1695. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1696. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1697. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1698. 'views' => $aViews,
  1699. 'votes' => $aVotes,
  1700. 'reactions' => $aReactions,
  1701. 'scores' => $aScores,
  1702. 'reports' => $aReports,
  1703. 'comments' => $aComments,
  1704. 'title' => $sTitle, //may be empty.
  1705. 'description' => '' //may be empty.
  1706. );
  1707. }
  1708. public function serviceGetTimelinePostAllowedView($aEvent)
  1709. {
  1710. $iContentId = (int)$aEvent['object_id'];
  1711. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1712. if(empty($aContentInfo) || !is_array($aContentInfo))
  1713. return _t('_sys_txt_access_denied');
  1714. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1715. }
  1716. /**
  1717. * Check particular action permission without content
  1718. * @param $sAction action to check, for example: Browse, Add
  1719. * @param $iContentId content ID
  1720. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1721. */
  1722. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1723. {
  1724. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1725. if (!method_exists($this, $sMethod))
  1726. return _t('_sys_request_method_not_found_cpt');
  1727. return $this->$sMethod($isPerformAction);
  1728. }
  1729. /**
  1730. * Check particular action permission with content
  1731. * @param $sAction action to check, for example: View, Edit
  1732. * @param $iContentId content ID
  1733. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1734. */
  1735. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1736. {
  1737. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1738. return _t('_sys_request_page_not_found_cpt');
  1739. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1740. if (!method_exists($this, $sMethod))
  1741. return _t('_sys_request_method_not_found_cpt');
  1742. return $this->$sMethod($aContentInfo, $isPerformAction);
  1743. }
  1744. /**
  1745. * Check particular action permission with content for specified profile
  1746. * @param $sAction action to check, for example: View, Edit
  1747. * @param $iContentId content ID
  1748. * @param $iProfileId profile ID which the permissions to be cheked for
  1749. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1750. */
  1751. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1752. {
  1753. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1754. return _t('_sys_request_page_not_found_cpt');
  1755. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1756. if (!method_exists($this, $sMethod))
  1757. return _t('_sys_request_method_not_found_cpt');
  1758. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1759. }
  1760. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1761. {
  1762. //negative id used in comments for reports
  1763. if ($iContentId < 0)
  1764. return CHECK_ACTION_RESULT_ALLOWED;
  1765. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1766. }
  1767. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1768. {
  1769. //negative id used in comments for reports
  1770. if ($iContentId < 0)
  1771. return CHECK_ACTION_RESULT_ALLOWED;
  1772. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1773. }
  1774. public function serviceGetContentOwnerProfileId ($iContentId)
  1775. {
  1776. $CNF = &$this->_oConfig->CNF;
  1777. // file owner must be author of the content or profile itself in case of profile based module
  1778. if ($iContentId) {
  1779. $sModule = $this->getName();
  1780. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1781. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1782. }
  1783. else {
  1784. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1785. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1786. }
  1787. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1788. }
  1789. else {
  1790. $iProfileId = bx_get_logged_profile_id();
  1791. }
  1792. return $iProfileId;
  1793. }
  1794. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1795. {
  1796. $sModule = $this->getName();
  1797. $oBadges = BxDolBadges::getInstance();
  1798. $aBadges = $oBadges->getData(array(
  1799. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1800. 'module' => $sModule,
  1801. 'object_id' => $iContentId
  1802. ));
  1803. $sResult = false;
  1804. bx_alert('system', 'get_badges', 0, 0, array(
  1805. 'module' => $sModule,
  1806. 'content_id' => $iContentId,
  1807. 'is_single' => $bIsSingle,
  1808. 'is_compact' => $bIsCompact,
  1809. 'badges' => $aBadges,
  1810. 'override_result' => &$sResult
  1811. ));
  1812. if($sResult !== false)
  1813. return $sResult;
  1814. if(empty($aBadges) || !is_array($aBadges))
  1815. return '';
  1816. if($bIsSingle)
  1817. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  1818. $aBadgesOutput = array();
  1819. foreach($aBadges as $aBadge)
  1820. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  1821. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  1822. 'bx_repeat:items' => $aBadgesOutput,
  1823. ));
  1824. }
  1825. /**
  1826. * @page service Service Calls
  1827. * @section bx_base_general Base Text
  1828. * @subsection bx_base_general-page_blocks Page Blocks
  1829. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  1830. *
  1831. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  1832. *
  1833. * Display multi-categorories block with number of posts in each category
  1834. * @param $bDisplayEmptyCats display empty categories
  1835. *
  1836. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  1837. */
  1838. /**
  1839. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  1840. */
  1841. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  1842. {
  1843. $oCategories = BxDolCategories::getInstance();
  1844. $aCats = $oCategories->getData(array('type' => 'by_module_with_num', 'module' => $this->getName()));
  1845. $aVars = array('bx_repeat:cats' => array());
  1846. foreach ($aCats as $oCat) {
  1847. $sValue = $oCat['value'];
  1848. $iNum = $oCat['num'];
  1849. $aVars['bx_repeat:cats'][] = array(
  1850. 'url' => $oCategories->getUrl($this->getName(), $sValue),
  1851. 'name' => _t($sValue),
  1852. 'value' => $sValue,
  1853. 'num' => $iNum,
  1854. );
  1855. }
  1856. if (!$aVars['bx_repeat:cats'])
  1857. return '';
  1858. return $this->_oTemplate->parseHtmlByName('category_list.html', $aVars);
  1859. }
  1860. /**
  1861. * ======
  1862. * PERMISSION METHODS
  1863. * ======
  1864. */
  1865. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1866. {
  1867. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1868. // check alert to allow custom checks
  1869. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1870. return $mixedResult;
  1871. }
  1872. public function checkAllowedSetThumb ($iContentId = 0)
  1873. {
  1874. return CHECK_ACTION_RESULT_ALLOWED;
  1875. }
  1876. /**
  1877. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1878. */
  1879. public function checkAllowedBrowse ()
  1880. {
  1881. // check alert to allow custom checks
  1882. $mixedResult = null;
  1883. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1884. if($mixedResult !== null)
  1885. return $mixedResult;
  1886. return CHECK_ACTION_RESULT_ALLOWED;
  1887. }
  1888. /**
  1889. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1890. */
  1891. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1892. {
  1893. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1894. }
  1895. /**
  1896. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1897. */
  1898. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  1899. {
  1900. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1901. }
  1902. /**
  1903. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1904. */
  1905. public function checkAllowedAdd ($isPerformAction = false)
  1906. {
  1907. // check ACL
  1908. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1909. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1910. return $aCheck[CHECK_ACTION_MESSAGE];
  1911. return CHECK_ACTION_RESULT_ALLOWED;
  1912. }
  1913. /**
  1914. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1915. */
  1916. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  1917. {
  1918. // moderator always have access
  1919. if ($this->_isModerator($isPerformAction))
  1920. return CHECK_ACTION_RESULT_ALLOWED;
  1921. // check for context's admins
  1922. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  1923. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1924. if ($oProfile){
  1925. $sModule = $oProfile->getModule();
  1926. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1927. $oModule = BxDolModule::getInstance($sModule);
  1928. // check for context's extra roles with rights
  1929. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1930. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  1931. if ($bResult !== NULL) return $bResult;
  1932. }
  1933. // if allowed edit a group then allowed to edit anything inside its context
  1934. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1935. return CHECK_ACTION_RESULT_ALLOWED;
  1936. }
  1937. }
  1938. }
  1939. return _t('_sys_txt_access_denied');
  1940. }
  1941. /**
  1942. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1943. */
  1944. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1945. {
  1946. // moderator and owner always have access
  1947. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1948. return CHECK_ACTION_RESULT_ALLOWED;
  1949. // check for context's admins
  1950. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  1951. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1952. if ($oProfile){
  1953. $sModule = $oProfile->getModule();
  1954. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1955. $oModule = BxDolModule::getInstance($sModule);
  1956. // check for context's extra roles with rights
  1957. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1958. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  1959. if ($bResult !== NULL) return $bResult;
  1960. }
  1961. // if allowed edit a group then allowed to edit anything inside its context
  1962. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1963. return CHECK_ACTION_RESULT_ALLOWED;
  1964. }
  1965. }
  1966. }
  1967. return _t('_sys_txt_access_denied');
  1968. }
  1969. /**
  1970. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1971. */
  1972. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1973. {
  1974. // moderator always has access
  1975. if ($this->_isAdministrator($isPerformAction))
  1976. return CHECK_ACTION_RESULT_ALLOWED;
  1977. // check ACL
  1978. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1979. 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)
  1980. return CHECK_ACTION_RESULT_ALLOWED;
  1981. // check for context's admins
  1982. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  1983. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1984. if ($oProfile){
  1985. $sModule = $oProfile->getModule();
  1986. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1987. $oModule = BxDolModule::getInstance($sModule);
  1988. // check for context's extra roles with rights
  1989. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1990. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  1991. if ($bResult !== NULL) return $bResult;
  1992. }
  1993. // if allowed delete a group then allowed to delete anything inside its context
  1994. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1995. return CHECK_ACTION_RESULT_ALLOWED;
  1996. }
  1997. }
  1998. }
  1999. return _t('_sys_txt_access_denied');
  2000. }
  2001. /**
  2002. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2003. */
  2004. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2005. {
  2006. // admin always has access
  2007. if (isAdmin())
  2008. return CHECK_ACTION_RESULT_ALLOWED;
  2009. // check ACL
  2010. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2011. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2012. return $aCheck[CHECK_ACTION_MESSAGE];
  2013. return CHECK_ACTION_RESULT_ALLOWED;
  2014. }
  2015. /**
  2016. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2017. */
  2018. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2019. {
  2020. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2021. }
  2022. /**
  2023. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2024. */
  2025. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2026. {
  2027. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2028. }
  2029. /**
  2030. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2031. */
  2032. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2033. {
  2034. if(!$iProfileId)
  2035. $iProfileId = $this->_iProfileId;
  2036. $aCheck = checkActionModule($iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  2037. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2038. return CHECK_ACTION_RESULT_ALLOWED;
  2039. return _t('_sys_txt_access_denied');
  2040. }
  2041. /**
  2042. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2043. */
  2044. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2045. {
  2046. if(!$iProfileId)
  2047. $iProfileId = $this->_iProfileId;
  2048. $aCheck = checkActionModule($iProfileId, 'delete any entry', $this->getName(), $isPerformAction);
  2049. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2050. return CHECK_ACTION_RESULT_ALLOWED;
  2051. return _t('_sys_txt_access_denied');
  2052. }
  2053. /**
  2054. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2055. */
  2056. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2057. {
  2058. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2059. }
  2060. /**
  2061. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2062. */
  2063. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2064. {
  2065. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2066. }
  2067. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2068. {
  2069. $CNF = &$this->_oConfig->CNF;
  2070. if(!$iProfileId)
  2071. $iProfileId = $this->_iProfileId;
  2072. if(empty($aDataEntry) || !is_array($aDataEntry))
  2073. return _t('_sys_txt_not_found');
  2074. // moderator and owner always have access
  2075. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2076. return CHECK_ACTION_RESULT_ALLOWED;
  2077. // check ACL
  2078. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2079. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2080. return $aCheck[CHECK_ACTION_MESSAGE];
  2081. // check privacy
  2082. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2083. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2084. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2085. return _t('_sys_access_denied_to_private_content');
  2086. }
  2087. return CHECK_ACTION_RESULT_ALLOWED;
  2088. }
  2089. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2090. {
  2091. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2092. return MsgBox($sMsg);
  2093. bx_import($sClassSearchResult, $this->_aModule);
  2094. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2095. $o = new $sClass($sMode, $aParams);
  2096. $o->setDesignBoxTemplateId($iDesignBox);
  2097. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2098. $o->setAjaxPaginate($bAjaxPaginate);
  2099. $o->setUnitParams(array('context' => $sMode));
  2100. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2101. $o->setCustomCurrentCondition($aParams['condition']);
  2102. if ($o->isError)
  2103. return '';
  2104. if ($s = $o->processing())
  2105. return $s;
  2106. else
  2107. return '';
  2108. }
  2109. /**
  2110. * Shows a list of profiles.
  2111. */
  2112. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2113. {
  2114. // get paginate object
  2115. $oPaginate = new BxTemplPaginate(array(
  2116. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2117. 'num' => count($aProfiles),
  2118. 'per_page' => $iLimit,
  2119. 'start' => $iStart,
  2120. ));
  2121. // remove last item from connection array, because we've got one more item for pagination calculations only
  2122. if (count($aProfiles) > $iLimit)
  2123. array_pop($aProfiles);
  2124. // get profiles HTML
  2125. $s = '';
  2126. foreach ($aProfiles as $mixedProfile) {
  2127. $bProfile = is_array($mixedProfile);
  2128. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2129. if(!$oProfile)
  2130. continue;
  2131. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2132. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2133. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2134. if($bProfile && is_array($mixedProfile['info']))
  2135. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2136. $s .= $oProfile->getUnit(0, $aUnitParams);
  2137. }
  2138. $aTmplVarsPaginate = [];
  2139. if($iStart || $oPaginate->getNum() > $iLimit)
  2140. $aTmplVarsPaginate = ['paginate' => $oPaginate->getSimplePaginate()];
  2141. return $this->_oTemplate->parseHtmlByName('browse_quick.html', array(
  2142. 'code' => $s,
  2143. 'bx_if:show_paginate' => [
  2144. 'condition' => !empty($aTmplVarsPaginate),
  2145. 'content' => $aTmplVarsPaginate
  2146. ]
  2147. ));
  2148. }
  2149. // ====== COMMON METHODS
  2150. public function onPublished($iContentId)
  2151. {
  2152. $CNF = &$this->_oConfig->CNF;
  2153. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2154. if(!$aContentInfo)
  2155. return;
  2156. $aParams = $this->_alertParams($aContentInfo);
  2157. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2158. }
  2159. public function onFailed($iContentId)
  2160. {
  2161. $CNF = &$this->_oConfig->CNF;
  2162. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2163. if(!$aContentInfo)
  2164. return;
  2165. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  2166. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2167. }
  2168. public function alertAfterAdd($aContentInfo) {}
  2169. public function alertAfterEdit($aContentInfo) {}
  2170. /**
  2171. * Get array of params to be passed in Add/Edit Alert.
  2172. */
  2173. protected function _alertParams($aContentInfo)
  2174. {
  2175. $CNF = &$this->_oConfig->CNF;
  2176. return array(
  2177. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2178. );
  2179. }
  2180. public function processMetasAdd($iContentId)
  2181. {
  2182. $CNF = &$this->_oConfig->CNF;
  2183. if(empty($CNF['OBJECT_METATAGS']))
  2184. return false;
  2185. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2186. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2187. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2188. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2189. if(!$bContentInfo)
  2190. return false;
  2191. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2192. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2193. $sKey = 'FIELD_LOCATION';
  2194. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2195. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2196. if(!empty($aLocation) && is_array($aLocation))
  2197. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2198. }
  2199. $sKey = 'FIELD_LABELS';
  2200. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2201. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2202. if(!empty($aLabels) && is_array($aLabels))
  2203. foreach ($aLabels as $sLabel)
  2204. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2205. }
  2206. return true;
  2207. }
  2208. public function processMetasEdit($iContentId, $oForm)
  2209. {
  2210. $CNF = &$this->_oConfig->CNF;
  2211. if(empty($CNF['OBJECT_METATAGS']))
  2212. return false;
  2213. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2214. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2215. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2216. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2217. if(!$bContentInfo)
  2218. return false;
  2219. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2220. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2221. $sKey = 'FIELD_LOCATION';
  2222. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2223. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2224. if(!empty($aLocation) && is_array($aLocation))
  2225. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2226. }
  2227. $sKey = 'FIELD_LABELS';
  2228. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2229. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2230. if(!empty($aLabels) && is_array($aLabels))
  2231. foreach ($aLabels as $sLabel)
  2232. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2233. }
  2234. return true;
  2235. }
  2236. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  2237. {
  2238. if(empty($aTranscoders))
  2239. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  2240. $CNF = &$this->_oConfig->CNF;
  2241. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  2242. return false;
  2243. $iId = (int)$aContentInfo[$CNF[$sField]];
  2244. foreach($aTranscoders as $sTranscoder)
  2245. if(!empty($CNF[$sTranscoder]))
  2246. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  2247. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2248. }
  2249. public function getProfileId()
  2250. {
  2251. return bx_get_logged_profile_id();
  2252. }
  2253. public function getProfileInfo($iUserId = false)
  2254. {
  2255. $oProfile = $this->getObjectUser($iUserId);
  2256. $oAccount = null;
  2257. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  2258. $oAccount = $oProfile->getAccountObject();
  2259. $bAccount = !empty($oAccount);
  2260. if(!$bAccount)
  2261. $oProfile = BxDolProfileUndefined::getInstance();
  2262. return array(
  2263. 'id' => $oProfile->id(),
  2264. 'name' => $oProfile->getDisplayName(),
  2265. 'email' => $bAccount ? $oAccount->getEmail() : '',
  2266. 'link' => $oProfile->getUrl(),
  2267. 'icon' => $oProfile->getIcon(),
  2268. 'thumb' => $oProfile->getThumb(),
  2269. 'avatar' => $oProfile->getAvatar(),
  2270. 'unit' => $oProfile->getUnit(),
  2271. 'active' => $oProfile->isActive(),
  2272. );
  2273. }
  2274. public function getObjectUser($iUserId = false)
  2275. {
  2276. bx_import('BxDolProfile');
  2277. return BxDolProfile::getInstanceMagic($iUserId);
  2278. }
  2279. public function getObjectFavorite($sSystem = '', $iId = 0)
  2280. {
  2281. $CNF = &$this->_oConfig->CNF;
  2282. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  2283. $sSystem = $CNF['OBJECT_FAVORITES'];
  2284. if(empty($sSystem))
  2285. return false;
  2286. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2287. if(!$oFavorite || !$oFavorite->isEnabled())
  2288. return false;
  2289. return $oFavorite;
  2290. }
  2291. public function getUserId()
  2292. {
  2293. return isLogged() ? bx_get_logged_profile_id() : 0;
  2294. }
  2295. public function getUserIp()
  2296. {
  2297. return getVisitorIP();
  2298. }
  2299. public function getUserInfo($iUserId = 0)
  2300. {
  2301. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2302. return array(
  2303. $oProfile->getDisplayName(),
  2304. $oProfile->getUrl(),
  2305. $oProfile->getThumb(),
  2306. $oProfile->getUnit(),
  2307. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  2308. );
  2309. }
  2310. public function getUserInfoWithBadges($iUserId = 0)
  2311. {
  2312. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2313. return array(
  2314. $oProfile->getDisplayName(),
  2315. $oProfile->getUrl(),
  2316. $oProfile->getThumb(),
  2317. $oProfile->getUnit(),
  2318. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  2319. $oProfile->getBadges()
  2320. );
  2321. }
  2322. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  2323. {
  2324. $CNF = &$this->_oConfig->CNF;
  2325. // default visible settings
  2326. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  2327. return false;
  2328. if (!empty($aItem['visibility_custom'])) {
  2329. $oMenu = BxDolMenu::getObjectInstance($sObject);
  2330. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  2331. return false;
  2332. }
  2333. // get custom function name to check menu item visibility
  2334. $sFuncCheckAccess = false;
  2335. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  2336. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  2337. // check custom visibility settings defined in module config class
  2338. if(!isset($aContentInfo))
  2339. $aContentInfo = array();
  2340. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  2341. return false;
  2342. return true;
  2343. }
  2344. public function _isModerator ($isPerformAction = false)
  2345. {
  2346. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  2347. }
  2348. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  2349. {
  2350. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  2351. }
  2352. public function _isAdministrator ($isPerformAction = false)
  2353. {
  2354. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  2355. }
  2356. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  2357. {
  2358. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  2359. }
  2360. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  2361. {
  2362. $CNF = &$this->_oConfig->CNF;
  2363. $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;
  2364. $AuditParams = array(
  2365. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2366. 'context_profile_id' => $iContextId,
  2367. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  2368. 'data' => ($bIsSaveData ? $aContentInfo : array())
  2369. );
  2370. if ($iContextId > 0)
  2371. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  2372. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  2373. return $AuditParams;
  2374. }
  2375. public function _getFavoriteListUrl ($iListId, $iProfileId)
  2376. {
  2377. $CNF = &$this->_oConfig->CNF;
  2378. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId);
  2379. }
  2380. // ====== PROTECTED METHODS
  2381. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  2382. {
  2383. $iContentId = $this->_getContent($iContentId, false);
  2384. if($iContentId === false)
  2385. return false;
  2386. bx_import('FormsEntryHelper', $this->_aModule);
  2387. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  2388. $oFormsHelper = new $sClass($this);
  2389. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  2390. }
  2391. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  2392. {
  2393. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => 'getContentInfoById'));
  2394. }
  2395. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  2396. {
  2397. if (!isset($aParams['function_get_content']))
  2398. $aParams['function_get_content'] = 'getContentInfoById';
  2399. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  2400. if($mixedContent === false)
  2401. return false;
  2402. list($iContentId, $aContentInfo) = $mixedContent;
  2403. if (isset($aParams['template_name']) && !empty($aParams['template_name']))
  2404. return $this->_oTemplate->$sFunc($aContentInfo, array('template_name' => $aParams['template_name']));
  2405. else
  2406. return $this->_oTemplate->$sFunc($aContentInfo);
  2407. }
  2408. protected function _rss ($aArgs, $sClass = 'SearchResult')
  2409. {
  2410. $sMode = array_shift($aArgs);
  2411. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  2412. $this->_oTemplate->displayAccessDenied ($sMsg);
  2413. exit;
  2414. }
  2415. $aParams = $this->_buildRssParams($sMode, $aArgs);
  2416. bx_import ($sClass, $this->_aModule);
  2417. $sClass = $this->_aModule['class_prefix'] . $sClass;
  2418. $o = new $sClass($sMode, $aParams);
  2419. if ($o->isError)
  2420. $this->_oTemplate->displayPageNotFound ();
  2421. else
  2422. $o->outputRSS();
  2423. exit;
  2424. }
  2425. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  2426. {
  2427. if(!$iContentId)
  2428. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2429. if(!$iContentId)
  2430. return false;
  2431. if($sFuncGetContent === true)
  2432. $sFuncGetContent = 'getContentInfoById';
  2433. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  2434. return $iContentId;
  2435. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  2436. if(!$aContentInfo)
  2437. return false;
  2438. return array($iContentId, $aContentInfo);
  2439. }
  2440. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2441. {
  2442. $CNF = &$this->_oConfig->CNF;
  2443. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2444. //--- Image(s)
  2445. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2446. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2447. //--- Video(s)
  2448. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2449. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2450. //--- Files(s)
  2451. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2452. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2453. //--- Title
  2454. $sTitle = '';
  2455. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  2456. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2457. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  2458. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2459. //--- Text
  2460. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2461. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  2462. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2463. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2464. }
  2465. return array(
  2466. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2467. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2468. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2469. 'url' => $sUrl,
  2470. 'title' => $sTitle,
  2471. 'text' => $sText,
  2472. 'images' => $aImages,
  2473. 'images_attach' => $aImagesAttach,
  2474. 'videos' => $aVideos,
  2475. 'videos_attach' => $aVideosAttach,
  2476. 'files' => $aFiles,
  2477. 'files_attach' => $aFilesAttach
  2478. );
  2479. }
  2480. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2481. {
  2482. $CNF = &$this->_oConfig->CNF;
  2483. $sImage = $sImageOrig = '';
  2484. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  2485. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2486. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2487. }
  2488. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  2489. if($sImage == '' && $bImageThumb)
  2490. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2491. if($sImageOrig == '' && $bImageThumb)
  2492. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2493. if(empty($sImage))
  2494. return array();
  2495. if($sImageOrig == '')
  2496. $sImageOrig = $sImage;
  2497. return array(
  2498. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  2499. );
  2500. }
  2501. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2502. {
  2503. return array();
  2504. }
  2505. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2506. {
  2507. return array();
  2508. }
  2509. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2510. {
  2511. return array();
  2512. }
  2513. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2514. {
  2515. return array();
  2516. }
  2517. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2518. {
  2519. return array();
  2520. }
  2521. protected function _entityComments ($sObject, $iId = 0)
  2522. {
  2523. if (!$iId)
  2524. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2525. if (!$iId)
  2526. return false;
  2527. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2528. if (!$oCmts || !$oCmts->isEnabled())
  2529. return false;
  2530. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
  2531. }
  2532. protected function _getFields($iContentId)
  2533. {
  2534. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2535. if(empty($aContentInfo))
  2536. return array();
  2537. return BxDolContentInfo::formatFields($aContentInfo);
  2538. }
  2539. protected function _getFieldValue($sField, $iContentId)
  2540. {
  2541. $CNF = &$this->_oConfig->CNF;
  2542. if(empty($CNF[$sField]))
  2543. return false;
  2544. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2545. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2546. return false;
  2547. return $aContentInfo[$CNF[$sField]];
  2548. }
  2549. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2550. {
  2551. $CNF = &$this->_oConfig->CNF;
  2552. if(empty($sTranscoder) || empty($CNF[$sField]))
  2553. return false;
  2554. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2555. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2556. return false;
  2557. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2558. if(!$oImagesTranscoder)
  2559. return false;
  2560. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2561. }
  2562. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2563. {
  2564. if(!$bAsJson)
  2565. return $aResponse;
  2566. if(!empty($aAdditional) && is_array($aAdditional))
  2567. $aResponse = array_merge($aResponse, $aAdditional);
  2568. echoJson($aResponse);
  2569. exit;
  2570. }
  2571. /**
  2572. * Blocks for lables tree browsing private functions
  2573. */
  2574. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2575. {
  2576. $oLabel = BxDolLabel::getInstance();
  2577. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2578. if ($aLabel){
  2579. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2580. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2581. }
  2582. }
  2583. private function _getLablesBrowseUrl($iLabelId)
  2584. {
  2585. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2586. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2587. }
  2588. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2589. {
  2590. $oLabel = BxDolLabel::getInstance();
  2591. $aLabelsOutput = array();
  2592. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2593. if (count($aLabels) > 0){
  2594. foreach($aLabels as $aLabel) {
  2595. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2596. $bChildPresent = $sChild != '' ? true : false;
  2597. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2598. if (!$bIsOpen){
  2599. $sChild = '';
  2600. }
  2601. $aLabelsOutput[] = array(
  2602. 'value' => $aLabel['value'],
  2603. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2604. 'child' => $sChild,
  2605. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2606. 'bx_if:open' => array(
  2607. 'condition' => $bChildPresent && $bIsOpen,
  2608. 'content' => array()
  2609. ),
  2610. 'bx_if:can_open' => array(
  2611. 'condition' => $bChildPresent && !$bIsOpen,
  2612. 'content' => array()
  2613. )
  2614. );
  2615. }
  2616. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2617. array(
  2618. 'bx_repeat:items' => $aLabelsOutput,
  2619. 'parent' => $iParent,
  2620. )
  2621. );
  2622. }
  2623. return '';
  2624. }
  2625. }
  2626. /** @} */