1
0

BxBaseModGeneralModule.php 93 KB

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