PageRenderTime 62ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_acajoom/bots/acajoombot.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 328 lines | 281 code | 41 blank | 6 comment | 55 complexity | 5f8660c13f612298c50c72139df9126d MD5 | raw file
  1. <?php
  2. if ( !defined('_JEXEC') && defined('_VALID_MOS') ) define( '_JEXEC', true );
  3. defined('_JEXEC') or die('...Direct Access to this location is not allowed...');
  4. ### Copyright (C) 2006-2007 Acajoom Services. All rights reserved.
  5. ### http://www.acajoom.com/license.php
  6. $_MAMBOTS->registerFunction('acajoombot_editabs', 'acajoombot_content_editab');
  7. $_MAMBOTS->registerFunction('acajoombot_transformall', 'acajoombot_content_transformall');
  8. $_MAMBOTS->registerFunction('acajoombot_transformall', 'acajoombot_jcalpro_transformall');
  9. $_MAMBOTS->registerFunction('acajoombot_transformfinal', 'acajoombot_class_transformfinal');
  10. function acajoombot_content_editab() {
  11. $content_items = acajoombot_content_getitems();
  12. ob_start();
  13. ?>
  14. <script type="text/javascript">
  15. <!--
  16. function selectFormFB(){
  17. if(!document.adminForm){
  18. return 'mosForm';
  19. }else{
  20. return 'adminForm';
  21. }
  22. }
  23. function selectFB(variable){
  24. var formname = selectFormFB();
  25. return eval('document.'+formname+'.'+variable);
  26. }
  27. function acajoombot_content_update_output() {
  28. // get the info
  29. var form = document.adminForm;
  30. if(!form){
  31. form = document.mosForm;
  32. }
  33. var content_id = form.content_id.options[form.content_id.selectedIndex].value;
  34. //changed to use radio instead of checkbox - p0stman911
  35. for (i=0;i<form.content_type.length;i++) {
  36. if (form.content_type[i].checked) {
  37. var content_type = form.content_type[i].value;
  38. }
  39. }
  40. // output the tag
  41. form.content_tag.value = "{contentitem:" + content_id + "|" + content_type + "}";
  42. } // end function
  43. //-->
  44. </script>
  45. <table class="acajoomcss_bots" width="100%">
  46. <tr>
  47. <td style="vertical-align: top;">
  48. <span class="editlinktip">
  49. <?php
  50. $tip = _ACA_TITLE_ONLY_TIPS ;
  51. $title = _ACA_TITLE_ONLY;
  52. $title_only = "<span class=\"editlinktip\">" . compa::toolTip( $tip, '', 280, 'tooltip.png', $title, '', 0 ) . "</span>";
  53. $tip = _ACA_INTRO_ONLY_TIPS;
  54. $title = _ACA_INTRO_ONLY;
  55. $intro_only = "<span class=\"editlinktip\">" . compa::toolTip( $tip, '', 280, 'tooltip.png', $title, '', 0 ) . "</span>";
  56. $tip = _ACA_FULL_ARTICLE_TIPS;
  57. $title = _ACA_FULL_ARTICLE ;
  58. $full_article = "<span class=\"editlinktip\">" . compa::toolTip( $tip, '', 280, 'tooltip.png', $title, '', 0 ) . "</span>";
  59. ?>
  60. </span>
  61. <br /><br />
  62. <span class="editlinktip">
  63. <input type="radio" name="content_type" value="0" checked="checked" onclick="acajoombot_content_update_output();" /><?php echo $full_article; ?>
  64. <input type="radio" name="content_type" value="1" onclick="acajoombot_content_update_output();" /><?php echo $intro_only; ?>
  65. <input type="radio" name="content_type" value="2" onclick="acajoombot_content_update_output();" /><?php echo $title_only; ?>
  66. </span>
  67. <br /><br />
  68. <span class="editlinktip">
  69. <?php
  70. $tip = _ACA_TAGS_TITLE_TIPS;
  71. $title = _ACA_TAGS_TITLE.': ';
  72. echo compa::toolTip( $tip, '', 280, 'tooltip.png', $title, '', 0 );
  73. ?>
  74. </span>
  75. <input type="text" name="content_tag" class="inputbox" size="20" onfocus="this.select();" />
  76. <br /><br />
  77. <select name="content_id" class="inputbox" size="30" onchange="acajoombot_content_update_output();">
  78. <?php
  79. if(sizeof($content_items) > 0) {
  80. foreach ($content_items AS $content_item) {
  81. echo '<option value="' . $content_item->id . '">' . $content_item->section . '/' . $content_item->category . '/'. $content_item->title . '</option>' . "\n";
  82. }
  83. }
  84. ?>
  85. </select>
  86. </td>
  87. </tr>
  88. </table>
  89. <?php
  90. $return = ob_get_contents();
  91. ob_end_clean();
  92. return array(_ACA_CONTENT_ITEM, $return);
  93. }
  94. function acajoombot_content_getitems() {
  95. global $database;
  96. $query = "SELECT a.id as id, a.title as title, b.title as section, c.title as category FROM #__content as a LEFT JOIN #__sections as b ON a.sectionid = b.id LEFT JOIN #__categories AS c ON a.catid = c.id ORDER BY a.sectionid, a.catid, a.created DESC";
  97. $database->setQuery($query);
  98. $contentitems = $database->loadObjectList();
  99. return $contentitems;
  100. }
  101. function acajoombot_content_transformall($html, $text) {
  102. global $mainframe, $_MAMBOTS;
  103. $content_items = array();
  104. preg_match_all('/\{contentitem:(.{1,8})\|(.{1})}/', $html, $content_items, PREG_SET_ORDER);
  105. foreach ($content_items as $content_item) {
  106. $Itemid = $mainframe->getItemId($content_item[1]);
  107. if(empty($Itemid)){
  108. $Itemid = $GLOBALS[ACA.'itemidAca'];
  109. }
  110. $replacement = acajoombot_content_getitem($content_item[1]);
  111. if ($GLOBALS[ACA.'show_author'] == 1){
  112. $author = '<br />'.$replacement->created_by_alias;
  113. }
  114. else{
  115. $author = '';
  116. }
  117. $replacement->introtext = str_replace('{mospagebreak}', '<div style="clear: both;" ><div />', $replacement->introtext);
  118. $replacement->fulltext = str_replace('{mospagebreak}', '<div style="clear: both;" ><div />', $replacement->fulltext);
  119. if ($content_item[2] == 0) {
  120. $html = str_replace($content_item[0], '<div class="contentpaneopen_nws"><span class="contentheading_nws">' . $replacement->title . '</span>' . "\r\n" . $author .'<br />' . $replacement->introtext . '<br />' . "\r\n" . $replacement->fulltext . "\r\n".'</div>', $html);
  121. } else {
  122. if ($GLOBALS[ACA.'use_sef'] == '1' AND $GLOBALS['mosConfig_sef'] == '1' AND function_exists('sefRelToAbs')) {
  123. $link = sefRelToAbs('index.php?option=com_content&task=view&id='.$content_item[1].'&Itemid='.$Itemid);
  124. } else {
  125. $link = $GLOBALS['mosConfig_live_site'].'/index.php?option=com_content&task=view&id='.$content_item[1].'&Itemid='.$Itemid;
  126. }
  127. if ($content_item[2] == 1) {
  128. $html = str_replace($content_item[0], '<div class="contentpaneopen_nws"><span class="contentheading_nws">' . $replacement->title . '</span>' . "\r\n" . $author .'<br />' . $replacement->introtext . '<br />' . "\r\n" . '<a href="' . $link . '"><span class="readon_nws">' . _READ_MORE . '</span></a>' . "\r\n".'</div>', $html);
  129. }
  130. else {
  131. $html = str_replace($content_item[0], '<a href="' . $link . '"><span class="contentheading_nws">' . $replacement->title . '</span></a>', $html);
  132. }
  133. }
  134. $images = acajoombot_content_getimage($replacement->images);
  135. foreach($images as $image) {
  136. $image_string = '<img src="' . $GLOBALS['mosConfig_live_site'] . '/images/stories/' . $image['image'] . '" align="' . $image['align'] . '" alt="' . $image['alttext'] . '" border="' . $image['border'] . '" />';
  137. $html = preg_replace('/{mosimage}/', $image_string, $html, 1);
  138. }
  139. }
  140. $content_items = array();
  141. preg_match_all('/\{contentitem:(.{1,5})\|(.{1})}/', $text, $content_items, PREG_SET_ORDER);
  142. foreach ($content_items as $content_item) {
  143. $Itemid = $mainframe->getItemId($content_item[1]);
  144. if(empty($Itemid)){
  145. $Itemid = $GLOBALS[ACA.'itemidAca'];
  146. }
  147. $replacement = acajoombot_content_getitem($content_item[1]);
  148. if ($GLOBALS[ACA.'show_author'] == 1){
  149. $author = "\r\n".$replacement->created_by_alias;
  150. }
  151. else{
  152. $author = '';
  153. }
  154. $replacement->title = strtoupper(acajoom_mail::htmlToText($replacement->title));
  155. $replacement->introtext = acajoom_mail::htmlToText($replacement->introtext);
  156. $replacement->fulltext = acajoom_mail::htmlToText($replacement->fulltext);
  157. if ($content_item[2] == 0) {
  158. $text = str_replace($content_item[0], $replacement->title . $author . "\r\n" . $replacement->introtext . "\r\n" . $replacement->fulltext . "\r\n", $text);
  159. } else {
  160. if ($GLOBALS[ACA.'use_sef'] == '1' AND $GLOBALS['mosConfig_sef'] == '1' AND function_exists('sefRelToAbs')) {
  161. $link = sefRelToAbs('index.php?option=com_content&task=view&id='.$content_item[1].'&Itemid='.$Itemid);
  162. } else {
  163. $link = $GLOBALS['mosConfig_live_site'].'/index.php?option=com_content&task=view&id='.$content_item[1].'&Itemid='.$Itemid;
  164. }
  165. if ($content_item[2] == 1) {
  166. $text = str_replace($content_item[0], $replacement->title . $author . "\r\n" . $replacement->introtext . "\r\n" . '* ' . _READ_MORE . ' ( '. $link . ' )' . "\r\n", $text);
  167. }
  168. else {
  169. $text = str_replace($content_item[0], $replacement->title . ' ( ' . $link . ' )', $text);
  170. }
  171. }
  172. $text = str_replace('{mosimage}', '', $text);
  173. }
  174. $html = str_replace('{mospagebreak}', '<div style="clear: both;" ><div />', $html);
  175. $text = str_replace('{mospagebreak}', "\r\n \r\n", $text);
  176. }
  177. function acajoombot_content_getitem($id) {
  178. global $database;
  179. $erro = new xerr( __FILE__ , __FUNCTION__ );
  180. $query = "SELECT a.title as title, a.sectionid as sectionid, a.catid as catid, a.introtext as introtext, b.name as name, a.created_by_alias as created_by_alias, a.fulltext as `fulltext`, a.images as images FROM #__content as a LEFT JOIN #__users as b ON a.created_by = b.id WHERE a.id = $id";
  181. $database->setQuery($query);
  182. $database->loadObject($content_item);
  183. $erro->err = $database->getErrorMsg();
  184. $erro->show();
  185. if($content_item->created_by_alias == ''){$content_item->created_by_alias = $content_item->name;}
  186. if (!$erro->E(__LINE__ , '8011') ) {
  187. return false;
  188. } else {
  189. if(get_magic_quotes_runtime()) {
  190. $content_item->title = stripslashes($content_item->title);
  191. $content_item->introtext = stripslashes($content_item->introtext);
  192. $content_item->fulltext = stripslashes($content_item->fulltext);
  193. $content_item->images = stripslashes($content_item->images);
  194. $content_item->created_by_alias = stripslashes($content_item->created_by_alias);
  195. $content_item->sectionid = stripslashes($content_item->sectionid);
  196. $content_item->catid = stripslashes($content_item->catid);
  197. }
  198. return $content_item;
  199. }
  200. }
  201. function acajoombot_content_getimage($images) {
  202. $first = @explode("\n",$images);
  203. for($i=0, $n=count($first); $i < $n; $i++) {
  204. $second = explode('|',$first[$i] . '|||');
  205. $third[$i]['image'] = $second[0];
  206. $third[$i]['align'] = $second[1];
  207. $third[$i]['alttext'] = $second[2];
  208. $third[$i]['border'] = $second[3];
  209. }
  210. return $third;
  211. }
  212. function acajoombot_jcalpro_transformall($html, $text) {
  213. global $database;
  214. $Itemid = $GLOBALS[ACA.'itemidAca'];
  215. preg_match_all('#{jcalevent:.{7,15}}#', $html.$text, $tags);
  216. $replace = array();
  217. $replacebyHTML = array();
  218. $replacebyText = array();
  219. if(!empty($tags[0])){
  220. foreach ($tags[0] as $tag){
  221. $isolate = explode(':',$tag);
  222. if(count($isolate)!=2) continue;
  223. $parameters = explode('|',$isolate[1]);
  224. if(count($parameters)!=4) continue;
  225. if(!empty($replace[$tag])) continue;
  226. $replace[$tag] = $tag;
  227. $query = 'SELECT `title`, `description`, `end_date`, `start_date`, `extid` from #__jcalpro_events where `extid` = '.intval($parameters[0]);
  228. $database->setQuery($query);
  229. $database->loadObject($event);
  230. if(empty($event->extid)){
  231. $replacebyHTML[$tag] = '';
  232. $replacebyText[$tag] = '';
  233. continue;
  234. }
  235. $eventhtml = '';
  236. if($parameters[2]){
  237. $eventhtml .= '<div class="eventpaneopen_nws">';
  238. }
  239. $eventhtml .= '<span class="eventheading_nws">' . $event->title . '</span>';
  240. $eventtext = strtoupper(acajoom_mail::htmlToText($event->title));
  241. if($parameters[1]){
  242. $start_date_array = (explode('-',$event->start_date));
  243. $start_time_array = (explode(':',substr($event->start_date,10,15)));
  244. $date = strftime(_DATE_FORMAT_LC, mktime($start_time_array[0], $start_time_array[1], 0, $start_date_array[1], $start_date_array[2], $start_date_array[0]));
  245. $eventhtml.= '<br/>'.$date;
  246. $eventtext.= "\r\n".$date;
  247. }
  248. if($parameters[2]){
  249. $eventhtml.= '<br/>'.$event->description;
  250. $eventtext.= "\r\n".acajoom_mail::htmlToText($event->description);
  251. }
  252. if($parameters[3]){
  253. if ($GLOBALS[ACA.'use_sef'] == '1' AND $GLOBALS['mosConfig_sef'] == '1' AND function_exists('sefRelToAbs')) {
  254. $link = sefRelToAbs('index.php?option=com_jcalpro&extmode=view&extid='.$event->extid.'&Itemid='.$Itemid);
  255. } else {
  256. $link = $GLOBALS['mosConfig_live_site'].'/index.php?option=com_jcalpro&extmode=view&extid='.$event->extid.'&Itemid='.$Itemid;
  257. }
  258. $eventhtml.= '<br/><a href="' . $link . '"><span class="readon_nws">' . _READ_MORE . '</span></a>';
  259. $eventtext.= "\r\n".' * ' . _READ_MORE . ' ( '. $link . ' )';
  260. }
  261. if($parameters[2]){
  262. $eventhtml .= '</div>';
  263. }
  264. $replacebyHTML[$tag] = $eventhtml;
  265. $replacebyText[$tag] = $eventtext;
  266. }
  267. }
  268. $html = str_replace($replace,$replacebyHTML,$html);
  269. $text = str_replace($replace,$replacebyText,$text);
  270. }
  271. function acajoombot_class_transformfinal($html, $text,$params = null) {
  272. global $database;
  273. $replace = array();
  274. $replaceby = array();
  275. $i = 0;
  276. if(!empty($params)){
  277. foreach($params as $class => $style){
  278. if(preg_match('#class_#',$class) AND !empty($style)){
  279. $class = str_replace('class_','',$class);
  280. $replace[$i] = 'class="'.$class.'"';
  281. $replaceby[$i] = 'style="'.$style.'"';
  282. $i++;
  283. }
  284. }
  285. }
  286. $html = str_replace($replace,$replaceby,$html);
  287. }