1
0

BxBaseModGeneralModule.php 123 KB

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