BxBaseModGeneralModule.php 112 KB

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