BxBaseModGeneralModule.php 124 KB

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