PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jfusion/models/model.abstractpublic.php

http://jfusion.googlecode.com/
PHP | 985 lines | 632 code | 105 blank | 248 comment | 97 complexity | 9e5e8aac09158b8e74d4a7dbd0b186b5 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion
  4. * @subpackage Models
  5. * @author JFusion development team
  6. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  8. */
  9. // no direct access
  10. defined('_JEXEC' ) or die('Restricted access' );
  11. /**
  12. * Abstract interface for all JFusion functions that are accessed through the Joomla front-end
  13. * @package JFusion
  14. */
  15. class JFusionPublic{
  16. /**
  17. * returns the name of this JFusion plugin
  18. * @return string name of current JFusion plugin
  19. */
  20. function getJname()
  21. {
  22. return '';
  23. }
  24. /**
  25. * Returns the registration URL for the integrated software
  26. * @return string registration URL
  27. */
  28. function getRegistrationURL()
  29. {
  30. return '';
  31. }
  32. /**
  33. * Returns the lost password URL for the integrated software
  34. * @return string lost password URL
  35. */
  36. function getLostPasswordURL()
  37. {
  38. return '';
  39. }
  40. /**
  41. * Returns the lost username URL for the integrated software
  42. * @return string lost username URL
  43. */
  44. function getLostUsernameURL()
  45. {
  46. return '';
  47. }
  48. /**
  49. * Returns Array of stdClass title / url
  50. * @return object Db columns assigned to title and url links for pathway
  51. */
  52. function getPathWay()
  53. {
  54. $path = new stdClass();
  55. $path->title = '';
  56. $path->url = '';
  57. $pathway[] = $path;
  58. return null;
  59. }
  60. /**
  61. * Returns the URL to a userprofile of the integrated software
  62. * @param integer $uid userid
  63. * @return string URL
  64. */
  65. function getProfileURL($uid)
  66. {
  67. return '';
  68. }
  69. /**
  70. * Retrieves the source path to the user's avatar
  71. * @param $uid software's user id
  72. * @return string with source path to users avatar
  73. */
  74. function getAvatar($uid)
  75. {
  76. return 0;
  77. }
  78. /**
  79. * Returns the URL to the view all private messages URL of the integrated software
  80. * @return string URL
  81. */
  82. function getPrivateMessageURL()
  83. {
  84. return '';
  85. }
  86. /**
  87. * Returns the URL to a view new private messages URL of the integrated software
  88. * @return string URL
  89. */
  90. function getViewNewMessagesURL()
  91. {
  92. return '';
  93. }
  94. /**
  95. * Returns the URL to a get private messages URL of the integrated software
  96. * @return string URL
  97. */
  98. function getPrivateMessageCounts($puser_id)
  99. {
  100. return 0;
  101. }
  102. /**
  103. * Prepares text for various areas
  104. *
  105. * @param string &$text Text to be modified
  106. * @param string $for (optional) Determines how the text should be prepared.
  107. * Options for $for as passed in by JFusion's plugins and modules are:
  108. * joomla (to be displayed in an article; used by discussion bot)
  109. * forum (to be published in a thread or post; used by discussion bot)
  110. * activity (displayed in activity module; used by the activity module)
  111. * search (displayed as search results; used by search plugin)
  112. * @param object $params (optional) Joomla parameter object passed in by JFusion's module/plugin
  113. * @param object $object (optional) Object with information for the specific element the text is from
  114. *
  115. * @return array $status Information passed back to calling script such as limit_applied
  116. */
  117. function prepareText(&$text, $for = '', $params = '', $object = '')
  118. {
  119. $status = array();
  120. if ($for == 'forum') {
  121. //first thing is to remove all joomla plugins
  122. preg_match_all('/\{(.*)\}/U', $text, $matches);
  123. //find each thread by the id
  124. foreach ($matches[1] AS $plugin) {
  125. //replace plugin with nothing
  126. $text = str_replace('{' . $plugin . '}', "", $text);
  127. }
  128. } elseif ($for == 'joomla' || ($for == 'activity' && $params->get('parse_text') == 'html')) {
  129. $options = array();
  130. if (!empty($params) && $params->get('character_limit', false)) {
  131. $status['limit_applied'] = 1;
  132. $options['character_limit'] = $params->get('character_limit');
  133. }
  134. JFusionFunction::parseCode($text, 'html', $options);
  135. } elseif ($for == 'search') {
  136. JFusionFunction::parseCode($text, 'plaintext');
  137. } elseif ($for == 'activity') {
  138. if ($params->get('parse_text') == 'plaintext') {
  139. $options = array();
  140. $options['plaintext_line_breaks'] = 'space';
  141. if ($params->get('character_limit')) {
  142. $status['limit_applied'] = 1;
  143. $options['character_limit'] = $params->get('character_limit');
  144. }
  145. JFusionFunction::parseCode($text, 'plaintext', $options);
  146. }
  147. }
  148. return $status;
  149. }
  150. /**
  151. * Parses custom BBCode defined in $this->prepareText() and called by the nbbc parser via JFusionFunction::parseCode()
  152. *
  153. * @return bbcode converted to html
  154. */
  155. function parseCustomBBCode ($bbcode, $action, $name, $default, $params, $content)
  156. {
  157. if ($action == 1) {
  158. return true;
  159. }
  160. $return = $content;
  161. switch ($name) {
  162. case 'size':
  163. $return = "<span style=\"font-size:$default\">$content</span>";
  164. break;
  165. case 'glow':
  166. $temp = explode(',', $default);
  167. $color = (!empty($temp[0])) ? $temp[0] : 'red';
  168. $return = "<span style=\"background-color:$color\">$content</span>";
  169. break;
  170. case 'shadow':
  171. $temp = explode(',', $default);
  172. $color = (!empty($temp[0])) ? $temp[0] : '#6374AB';
  173. $dir = (!empty($temp[1])) ? $temp[1] : 'left';
  174. $x = ($dir == 'left') ? '-0.2em' : '0.2em';
  175. $return = "<span style=\"text-shadow: $colo $x 0.1em 0.2em;\">$content</span>";
  176. break;
  177. case 'move':
  178. $return = "<marquee>$content</marquee>";
  179. break;
  180. case 'pre':
  181. $return = "<pre>$content</pre>";
  182. break;
  183. case 'hr':
  184. return '<hr>';
  185. break;
  186. case 'flash':
  187. $temp = explode(',', $default);
  188. $width = (!empty($temp[0])) ? $temp[0] : '200';
  189. $height = (!empty($temp[1])) ? $temp[1] : '200';
  190. $return = "<object classid='clsid:D27CDB6E-AE6D-11CF-96B8-444553540000' codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0' width='$width' height='$height'><param name='movie' value='$content' /><param name='play' value='false' /><param name='loop' value='false' /><param name='quality' value='high' /><param name='allowScriptAccess' value='never' /><param name='allowNetworking' value='internal' /><embed src='$content' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' width='$width' height='$height' play='false' loop='false' quality='high' allowscriptaccess='never' allownetworking='internal'></embed></object>";
  191. break;
  192. case 'ftp':
  193. if (empty($default)) {
  194. $default = $content;
  195. }
  196. $return = "<a href='$content'>$default</a>";
  197. break;
  198. case 'table':
  199. $return = "<table>$content</table>";
  200. break;
  201. case 'tr':
  202. $return = "<tr>$content</tr>";
  203. break;
  204. case 'td':
  205. $return = "<td>$content</td>";
  206. break;
  207. case 'tt';
  208. $return = "<tt>$content</tt>";
  209. break;
  210. case 'o':
  211. case 'O':
  212. case '0':
  213. $return = "<li type='circle'>$content</li>";
  214. break;
  215. case '*':
  216. case '@':
  217. $return = "<li type='disc'>$content</li>";
  218. break;
  219. case '+':
  220. case 'x':
  221. case '#':
  222. $return = "<li type='square'>$content</li>";
  223. break;
  224. case 'abbr':
  225. if (empty($default)) {
  226. $default = $content;
  227. }
  228. $return = "<abbr title='$default'>$content</abbr>";
  229. break;
  230. case 'anchor':
  231. if (!empty($default)) {
  232. $return = "<span id='$default'>$content</span>";
  233. } else {
  234. $return = $content;
  235. }
  236. break;
  237. case 'black':
  238. case 'blue':
  239. case 'green':
  240. case 'red':
  241. case 'white':
  242. $return = "<span style='color: $name;'>$content</span>";
  243. break;
  244. case 'iurl':
  245. if (empty($default)) {
  246. $default = $content;
  247. }
  248. $return = "<a href='" . htmlspecialchars($default) . "' class='bbcode_url' target='_self'>$content</a>";
  249. break;
  250. case 'html':
  251. case 'nobbc':
  252. case 'php':
  253. $return = $content;
  254. break;
  255. case 'ltr':
  256. $return = "<div style='text-align: left;' dir='$name'>$content</div>";
  257. break;
  258. case 'rtl':
  259. $return = "<div style='text-align: right;' dir='$name'>$content</div>";
  260. break;
  261. case 'me':
  262. $return = "<div style='color: red;'>* $default $content</div>";
  263. break;
  264. case 'time':
  265. $return = date("Y-m-d H:i", $content);
  266. break;
  267. default:
  268. break;
  269. }
  270. return $return;
  271. }
  272. /************************************************
  273. * Functions For JFusion Search Plugin
  274. ***********************************************/
  275. /**
  276. * Retrieves the search results to be displayed. Placed here so that plugins that do not use the database can retrieve and return results
  277. * @param $text string text to be searched
  278. * @param $phrase string how the search should be performed exact, all, or any
  279. * @param $pluginParam custom plugin parameters in search.xml
  280. * @param $itemid what menu item to use when creating the URL
  281. * @return array of results as objects
  282. * Each result should include:
  283. * $result->title = title of the post/article
  284. * $result->section = (optional) section of the post/article (shows underneath the title; example is Forum Name / Thread Name)
  285. * $result->text = text body of the post/article
  286. * $result->href = link to the content (without this, joomla will not display a title)
  287. * $result->browsernav = 1 opens link in a new window, 2 opens in the same window
  288. * $result->created = (optional) date when the content was created
  289. *
  290. * @param string &$text string text to be searched
  291. * @param string &$phrase string how the search should be performed exact, all, or any
  292. * @param object &$pluginParam custom plugin parameters in search.xml
  293. * @param int $itemid what menu item to use when creating the URL
  294. * @param string $ordering ordering sent by Joomla: null, oldest, popular, category, alpha, or newest
  295. *
  296. * @return array of results as objects
  297. */
  298. function getSearchResults(&$text, &$phrase, &$pluginParam, $itemid, $ordering)
  299. {
  300. //initialize plugin database
  301. $db = & JFusionFactory::getDatabase($this->getJname());
  302. //get the query used to search
  303. $query = $this->getSearchQuery($pluginParam);
  304. //assign specific table colums to title and text
  305. $columns = $this->getSearchQueryColumns();
  306. //build the query
  307. if($phrase == 'exact') {
  308. $where = "((LOWER({$columns->title}) LIKE '%$text%') OR (LOWER({$columns->text}) like '%$text%'))";
  309. } else {
  310. $words = explode (' ', $text);
  311. $wheres = array();
  312. foreach($words as $word) {
  313. $wheres[] = "((LOWER({$columns->title}) LIKE '%$word%') OR (LOWER({$columns->text}) like '%$word%'))";
  314. }
  315. if($phrase == 'all') $separator = "AND";
  316. else $separator = "OR";
  317. $where = '(' . implode ( ") $separator (", $wheres) . ')';
  318. }
  319. //pass the where clause into the plugin in case it wants to add something
  320. $this->getSearchCriteria($where, $pluginParam, $ordering);
  321. $query .= " WHERE $where";
  322. //add a limiter if set
  323. $limit = $pluginParam->get('search_limit','');
  324. if(!empty($limit)) {
  325. $db->setQuery($query,0,$limit);
  326. } else {
  327. $db->setQuery($query);
  328. }
  329. $results = $db->loadObjectList();
  330. //pass results back to the plugin in case they need to be filtered
  331. $this->filterSearchResults($results, $pluginParam);
  332. //load the results
  333. if(is_array($results)) {
  334. foreach($results as $result) {
  335. //add a link
  336. $href = JFusionFunction::routeURL($this->getSearchResultLink($result), $itemid, $this->getJname(), false);
  337. $result->href = $href;
  338. //open link in same window
  339. $result->browsernav = 2;
  340. //clean up the text such as removing bbcode, etc
  341. $this->prepareText($result->text, 'search', $pluginParam, $result);
  342. $this->prepareText($result->title, 'search', $pluginParam, $result);
  343. $this->prepareText($result->section, 'search', $pluginParam, $result);
  344. }
  345. }
  346. return $results;
  347. }
  348. /**
  349. * Assigns specific db columns to title and text of content retrieved
  350. * @return object Db columns assigned to title and text of content retrieved
  351. */
  352. function getSearchQueryColumns()
  353. {
  354. $columns = new stdClass();
  355. $columns->title = '';
  356. $columns->text = '';
  357. return $columns;
  358. }
  359. /**
  360. * Generates SQL query for the search plugin that does not include where, limit, or order by
  361. * @param object &$pluginParam custom plugin parameters in search.xml
  362. * @return string Returns query string
  363. */
  364. function getSearchQuery(&$pluginParam)
  365. {
  366. return '';
  367. }
  368. /**
  369. * Add on a plugin specific clause;
  370. * @param $where reference to where clause already generated by search bot; add on plugin specific criteria
  371. * @param object &$pluginParam custom plugin parameters in search.xml
  372. * @param string $ordering ordering sent by Joomla: null, oldest, popular, category, alpha, or newest
  373. * @return string Returns search criteria
  374. */
  375. function getSearchCriteria(&$where, &$pluginParam, $ordering)
  376. {
  377. }
  378. /**
  379. * Filter out results from the search ie forums that a user does not have permission to
  380. * @param object &$pluginParam custom plugin parameters in search.xml
  381. * @param $results object list of search query results
  382. */
  383. function filterSearchResults(&$results, &$pluginParam)
  384. {
  385. }
  386. /**
  387. * Returns the URL for a post
  388. * @param $vars mixed
  389. * @return string with URL
  390. */
  391. function getSearchResultLink($vars)
  392. {
  393. return '';
  394. }
  395. /************************************************
  396. * Functions For JFusion Who's Online Module
  397. ***********************************************/
  398. /**
  399. * Returns a query to find online users
  400. * Make sure columns are named as userid, username, username_clean (if applicable), name (of user), and email
  401. * @param $limit integer to use as a limiter for the number of results returned
  402. * @param $usergroups optional array or string of group ids
  403. */
  404. function getOnlineUserQuery($limit, $usergroups = "")
  405. {
  406. return '';
  407. }
  408. /**
  409. * Returns number of guests
  410. * @return int
  411. */
  412. function getNumberOnlineGuests()
  413. {
  414. return 0;
  415. }
  416. /**
  417. * Returns number of logged in users
  418. * @param $usergrups optonal array or string of usergroups for filtering purposes
  419. * @param $total optional boolean to show a count of all members or only those belonging to set usergroups
  420. * @return int
  421. */
  422. function getNumberOnlineMembers($usergroups = '', $total = 1)
  423. {
  424. return 0;
  425. }
  426. /**
  427. * Set the language from Joomla to the integrated software
  428. * @todo - To implement after the release RC 1.1.2
  429. *
  430. * @param object $userinfo - it can be null if the user is not logged for example.
  431. */
  432. function setLanguageFrontEnd($userinfo = null){
  433. $status = array();
  434. $status['error'] = '';
  435. $status['debug'] = JText::_( 'METHOD_NOT_IMPLEMENTED' );
  436. return $status;
  437. }
  438. /************************************************
  439. * Functions For JFusion Activity Module
  440. ***********************************************/
  441. /**
  442. * Returns the an array with SQL statements used by the activity module
  443. * @return array
  444. */
  445. function getActivityQuery($usedforums, $result_order, $result_limit)
  446. {
  447. return 0;
  448. }
  449. /**
  450. * Filter forums from a set of results sent in / useful if the plugin needs to restrict the forums visible to a user
  451. * @param $results set of results from query
  452. * @param $limit int limit results parameter as set in the module's params; used for plugins that cannot limit using a query limiter
  453. */
  454. function filterActivityResults(&$results, $limit=0)
  455. {
  456. }
  457. /*
  458. * Frameless Abscract functions
  459. */
  460. /**
  461. * gets the visual html output from the plugin
  462. */
  463. function getBuffer(&$data)
  464. {
  465. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.curlframeless.php');
  466. $status = JFusionCurlFrameless::display($data);
  467. if ( isset($data->location) ) {
  468. $location = str_replace($data->integratedURL,'',$data->location);
  469. $location = $this->fixUrl($location,$data->baseURL,$data->fullURL,$data->integratedURL,$data->jroute);
  470. $mainframe = & JFactory::getApplication();
  471. $mainframe->redirect($location);
  472. }
  473. if ( isset($status['error']) ) {
  474. foreach ( $status['error'] as $key => $value ) {
  475. JError::raiseWarning(500, $value);
  476. }
  477. }
  478. }
  479. /**
  480. * function that parses the HTML body and fixes up URLs and form actions
  481. * @param string the HTML body output generated by getBuffer()
  482. * @param string $baseURL the base joomla URL to add variables to
  483. * @param string $fullURL the full URL to the current page
  484. * @param string $integratedURL the URL to the integrated software
  485. * @return object userinfo Object containing the user information
  486. */
  487. function parseBody(&$data)
  488. {
  489. $regex_body = array();
  490. $replace_body = array();
  491. $params = JFusionFactory::getParams($this->getJname());
  492. // $regex_body[] = '#(href|action)=["|\']'.$data->integratedURL.'(.*?)["|\']#mS';
  493. // $replace_body[] = '$1="/$2"';
  494. // $regex_body[] = '#(href|action)=["|\'](?!\w{0,10}://|\w{0,10}:)(.\S*?)["|\']#mSie';
  495. // $replace_body[] = '\'$1="\'.$this->fixUrl("$2","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'").\'"\'';
  496. if (substr($data->baseURL, -1) != '/'){
  497. $urlMode = 1;
  498. } else if ($data->jroute==1) {
  499. $urlMode = 2;
  500. } else {
  501. $urlMode = 3;
  502. }
  503. //parse anchors
  504. if(!empty($data->parse_anchors)) {
  505. $regex_body[] = '#href="\#(.*?)"#mS';
  506. $replace_body[] = 'href="'.$data->fullURL.'#$1"';
  507. }
  508. //parse absolute URLS
  509. if(!empty($data->parse_abs_path)) {
  510. $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $data->integratedURL );
  511. $path = preg_replace('#//+#','/',"/$path/");
  512. $regex_body[] = '#(action="|href="|src="|background="|url\(\'?)'.$path.'(.*?)("|\'?\))#mS';
  513. $replace_body[] = '$1'.$data->integratedURL.'$2$3';
  514. switch ($urlMode) {
  515. case 1:
  516. case 2:
  517. $regex_body[] = '#href="'.$path.'(.*?)"#me';
  518. $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
  519. break;
  520. case 3:
  521. $regex_body[] = '#href="'.$path.'(.*?)"#mS';
  522. $replace_body[] = 'href="'.$data->baseURL.'$1"';
  523. break;
  524. }
  525. }
  526. //parse relative URLS
  527. if(!empty($data->parse_rel_url)) {
  528. switch ($urlMode) {
  529. case 1:
  530. case 2:
  531. $regex_body[] = '#href="[./|/](.*?)"#me';
  532. $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
  533. $regex_body[] = '#href="(?!\w{0,10}://|\w{0,10}:)(.*?)"#me';
  534. $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
  535. break;
  536. case 3:
  537. $regex_body[] = '#href="[./| /](.*?)"#mS';
  538. $replace_body[] = 'href="'.$data->baseURL.'$1"';
  539. $regex_body[] = '#href="(?!\w{0,10}://|\w{0,10}:)(.*?)"#mS';
  540. $replace_body[] = 'href="'.$data->baseURL.'$1"';
  541. break;
  542. }
  543. }
  544. //parse absolute URLS
  545. if(!empty($data->parse_abs_url)) {
  546. switch ($urlMode) {
  547. case 1:
  548. case 2:
  549. $regex_body[] = '#href="'.$data->integratedURL.'(.*?)"#me';
  550. $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
  551. break;
  552. case 3:
  553. $regex_body[] = '#href="'.$data->integratedURL.'(.*?)"#mS';
  554. $replace_body[] = 'href="'.$data->baseURL.'$1"';
  555. break;
  556. }
  557. }
  558. //convert relative links from images into absolute links
  559. if(!empty($data->parse_rel_img)) {
  560. $regex_body[] = '#(src="|background="|url\()[./|/](.*?)("|\))#mS';
  561. $replace_body[] = '$1'.$data->integratedURL.'$2$3';
  562. $regex_body[] = '#(src="|background="|url\()(?!\w{0,10}://|\w{0,10}:)(.*?)("|\))#mS';
  563. $replace_body[] = '$1'.$data->integratedURL.'$2$3';
  564. }
  565. //parse form actions
  566. if(!empty($data->parse_action)) {
  567. switch ($urlMode) {
  568. case 1:
  569. case 2:
  570. if (!empty($data->parse_abs_path)) {
  571. $regex_body[] = '#action="'.$path.'(.*?)"(.*?)>#me';
  572. $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
  573. }
  574. if (!empty($data->parse_abs_url)) {
  575. $regex_body[] = '#action="'.$data->integratedURL.'(.*?)"(.*?)>#me';
  576. $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
  577. }
  578. if (!empty($data->parse_rel_url)) {
  579. $regex_body[] = '#action="[./|/](.*?)"(.*?)>#me';
  580. $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
  581. }
  582. break;
  583. case 3:
  584. if (!empty($data->parse_abs_path)) {
  585. $regex_body[] = '#action="'.$path.'(.*?)"#mS';
  586. $replace_body[] = 'action="'.$data->baseURL.'$1"';
  587. }
  588. if (!empty($data->parse_abs_url)) {
  589. $regex_body[] = '#action="'.$data->integratedURL.'(.*?)"#mS';
  590. $replace_body[] = 'action="'.$data->baseURL.'$1"';
  591. }
  592. if (!empty($data->parse_rel_url)) {
  593. $regex_body[] = '#action="[./|/](.*?)"#mS';
  594. $replace_body[] = 'action="'.$data->baseURL.'$1"';
  595. }
  596. break;
  597. }
  598. }
  599. //parse relative popup links to full url links
  600. if(!empty($data->parse_popup)) {
  601. $regex_body[] = "#window\.open\('(?!\w{0,10}://)(.*?)'\)#mS";
  602. $replace_body[] = 'window.open(\''.$data->integratedURL.'$1\'';
  603. }
  604. $value = $data->bodymap;
  605. if(is_array($value)) {
  606. foreach ($value['value'] as $key => $val) {
  607. $regex = html_entity_decode($value['value'][$key]);
  608. $regex = rtrim($regex,';');
  609. $regex = eval("return '$regex';");
  610. $replace = html_entity_decode($value['name'][$key]);
  611. $replace = rtrim($replace,';');
  612. $replace = eval("return '$replace';");
  613. if ($regex && $replace) {
  614. $regex_body[] = $regex;
  615. $replace_body[] = $replace;
  616. }
  617. }
  618. }
  619. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  620. if ( method_exists($this , '_parseBody') ) {
  621. $this->_parseBody($data);
  622. }
  623. }
  624. /**
  625. * function that parses the HTML header and fixes up URLs
  626. * @param string $buffer the output generated by getBuffer()
  627. * @param string $baseURL the base joomla URL to add variables to
  628. * @param string $fullURL the full URL to the current page
  629. * @param string $integratedURL the URL to the integrated software
  630. * @return object userinfo Object containing the user information
  631. */
  632. function parseHeader(&$data)
  633. {
  634. // Define our preg arrays
  635. $regex_header = array();
  636. $replace_header = array();
  637. $params = JFusionFactory::getParams($this->getJname());
  638. //convert relative links into absolute links
  639. $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $data->integratedURL );
  640. $path = preg_replace('#//+#','/',"/$path/");
  641. $regex_header[] = '#(href|src)=[\'|"]'.$path.'(.*?)[\'|"]#Si';
  642. $replace_header[] = '$1="'.$data->integratedURL.'$2"';
  643. $regex_header[] = '#(href|src)=[\'|"](./|/)(.*?)[\'|"]#iS';
  644. $replace_header[] = '$1="'.$data->integratedURL.'$3"';
  645. $regex_header[] = '#(href|src)=["|\'](?!\w{0,10}://)(.*?)["|\']#mSi';
  646. $replace_header[] = '$1="'.$data->integratedURL.'$2"';
  647. $regex_header[] = '#@import(.*?)[\'"]'.$path.'(.*?)[\'"]#Sis';
  648. $replace_header[] = '@import$1"'.$data->integratedURL.'$2"';
  649. $regex_header[] = '#@import(.*?)[\'"]/(.*?)[\'"]#Sis';
  650. $replace_header[] = '@import$1"'.$data->integratedURL.'$2"';
  651. //fix for URL redirects
  652. $parse_redirect = $params->get('parse_redirect');
  653. if(!empty($parse_redirect)) {
  654. $regex_header[] = '#<meta http-equiv=[\'|"]refresh[\'|"] content=[\'|"](.*?)[\'|"](.*?)>#meis';
  655. $replace_header[] = '$this->fixRedirect("$1","'.$data->baseURL.'","'.$data->integratedURL.'","'.$data->jroute.'")';
  656. }
  657. $value = $data->headermap;
  658. if(is_array($value)) {
  659. foreach ($value['value'] as $key => $val) {
  660. $regex = html_entity_decode($value['value'][$key]);
  661. $regex = rtrim($regex,';');
  662. $regex = eval("return '$regex';");
  663. $replace = html_entity_decode($value['name'][$key]);
  664. $replace = rtrim($replace,';');
  665. $replace = eval("return '$replace';");
  666. if ($regex && $replace) {
  667. $regex_header[] = $regex;
  668. $replace_header[] = $replace;
  669. }
  670. }
  671. }
  672. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  673. if ( method_exists($this , '_parseHeader') ) {
  674. $this->_parseHeader($data);
  675. }
  676. }
  677. /**
  678. * extends JFusion's parseRoute function to reconstruct the SEF URL
  679. *
  680. * @param array $vars vars already parsed by JFusion's router.php file
  681. *
  682. */
  683. function parseRoute(&$vars)
  684. {
  685. }
  686. /**
  687. * extends JFusion's buildRoute function to build the SEF URL
  688. *
  689. * @param array &$segments query already prepared by JFusion's router.php file
  690. */
  691. function buildRoute(&$segments)
  692. {
  693. }
  694. function fixUrl($q='',$baseURL,$fullURL,$integratedURL,$jRoute)
  695. {
  696. if (substr($baseURL, -1) != '/') {
  697. //non sef URls
  698. $q = str_replace('?', '&amp;', $q);
  699. $url = $baseURL . '&amp;jfile=' .$q;
  700. } else if ($jRoute==1) {
  701. $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
  702. } else {
  703. //we can just append both variables
  704. $url = $baseURL . $q;
  705. }
  706. return $url;
  707. }
  708. function fixAction($url, $extra, $baseURL,$jRoute)
  709. {
  710. $url = htmlspecialchars_decode($url);
  711. $Itemid = JRequest::getInt('Itemid');
  712. //strip any leading dots
  713. if(substr($url,0,2)== './'){
  714. $url = substr($url,2);
  715. }
  716. if (substr($baseURL, -1) != '/'){
  717. //non-SEF mode
  718. $url_details = parse_url($url);
  719. $url_variables = array();
  720. if (isset($url_details['query'])) parse_str($url_details['query'], $url_variables);
  721. $jfile = basename($url_details['path']);
  722. //set the correct action and close the form tag
  723. $replacement = 'action="'.$baseURL . '"' . $extra . '>';
  724. $replacement .= '<input type="hidden" name="jfile" value="'. $jfile . '"/>';
  725. $replacement .= '<input type="hidden" name="Itemid" value="'.$Itemid . '"/>';
  726. $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
  727. } else if ($jRoute==1) {
  728. //extensive SEF parsing was selected
  729. $url = JFusionFunction::routeURL($url, $Itemid);
  730. $replacement = 'action="'.$url . '"' . $extra . '>';
  731. return $replacement;
  732. } else {
  733. //simple SEF mode
  734. $url_details = parse_url($url);
  735. $url_variables = array();
  736. if (isset($url_details['query'])) parse_str($url_details['query'], $url_variables);
  737. $jfile = basename($url_details['path']);
  738. $replacement = 'action="'.$baseURL . $jfile.'"' . $extra . '>';
  739. }
  740. unset($url_variables['option'],$url_variables['jfile'],$url_variables['Itemid']);
  741. //add any other variables
  742. if(is_array($url_variables)){
  743. foreach ($url_variables as $key => $value){
  744. $replacement .= '<input type="hidden" name="'. $key .'" value="'.$value . '"/>';
  745. }
  746. }
  747. return $replacement;
  748. }
  749. function fixRedirect($url, $baseURL, $integratedURL,$jRoute)
  750. {
  751. //split up the timeout from url
  752. preg_match( '#(.*?)url=(.*?)\z#i' , $url ,$parts );
  753. $timeout = $parts[1];
  754. $url = $parts[2];
  755. $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $integratedURL );
  756. $path = preg_replace('#//+#','/',"/$path/");
  757. $regex_url[] = '#'.$integratedURL.'(.*?)#mS';
  758. $replace_url[] = '$1';
  759. $regex_url[] = '#'.$path.'(.*?)#mS';
  760. $replace_url[] = '$1';
  761. $url = preg_replace($regex_url, $replace_url, $url);
  762. $url = $this->fixUrl($url,$baseURL,$baseURL,$integratedURL,$jRoute);
  763. $return = '<meta http-equiv="refresh" content="'.$timeout.'url=' . $url .'">';
  764. return $return;
  765. }
  766. /**
  767. * function that parses the HTML and fix the css
  768. * @param string $html data to parse
  769. * @param string $infile_only parse only infile (body)
  770. */
  771. function parseCSS(&$data,&$html,$infile_only=false)
  772. {
  773. $jname = $this->getJname();
  774. $param =& JFusionFactory::getParams ( $this->getJname() );
  775. if (empty($jname)) {
  776. $jname = JRequest::getVar ( 'Itemid' );
  777. }
  778. $document = JFactory::getDocument();
  779. $sourcepath = JPATH_SITE . DS . 'components' . DS . 'com_jfusion' . DS . 'css' . DS .$jname . DS;
  780. $urlpath = 'components/com_jfusion/css/'.$jname.'/';
  781. jimport('joomla.filesystem.file');
  782. jimport('joomla.filesystem.folder');
  783. JFolder::create($sourcepath.'infile');
  784. if (!$infile_only) {
  785. //Outputs: apearpearle pear
  786. $urlPattern = array('http://', 'https://', '.css', '\\', '/', '|', '*', ':', ';', '?', '"', '<', '>', '=', '&');
  787. $urlReplace = array('', '', '', '', '-', '', '', '', '', '', '', '', '', ',', '_');
  788. if ($data->parse_css) {
  789. if (preg_match_all( '#<link(.*?type=[\'|"]text\/css[\'|"][^>]*)>#Si', $html, $css )) {
  790. $regex_header = array ();
  791. $replace_header = array ();
  792. require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'parsers' . DS . 'css.php');
  793. jimport('joomla.filesystem.file');
  794. foreach ($css[1] as $key => $values) {
  795. if( preg_match( '#href=[\'|"](.*?)[\'|"]#Si', $values, $cssUrl )) {
  796. $cssUrlRaw = $cssUrl[1];
  797. $cssUrl = urldecode(htmlspecialchars_decode($cssUrl[1]));
  798. if ( preg_match( '#media=[\'|"](.*?)[\'|"]#Si', $values, $cssMedia ) ) {
  799. $cssMedia = $cssMedia[1];
  800. } else {
  801. $cssMedia = '';
  802. }
  803. $filename = str_replace($urlPattern, $urlReplace, $cssUrl).'.css';
  804. $filenamesource = $sourcepath.$filename;
  805. if ( !JFile::exists($filenamesource) ) {
  806. $cssparser = new cssparser('#jfusionframeless');
  807. $result = $cssparser->ParseUrl($cssUrlRaw);
  808. if ($result !== false ) {
  809. $content = $cssparser->GetCSS();
  810. JFile::write($filenamesource, $content);
  811. }
  812. }
  813. if ( JFile::exists($filenamesource) ) {
  814. $html = str_replace($cssUrlRaw , $urlpath.$filename , $html );
  815. }
  816. }
  817. }
  818. }
  819. }
  820. }
  821. if ($data->parse_infile_css) {
  822. if (preg_match_all( '#<style.*?type=[\'|"]text/css[\'|"].*?>(.*?)</style>#Sims', $html, $css )) {
  823. require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'parsers' . DS . 'css.php');
  824. foreach ($css[1] as $key => $values) {
  825. $filename = md5($values).'.css';
  826. $filenamesource = $sourcepath.'infile'.DS.$filename;
  827. if ( preg_match( '#media=[\'|"](.*?)[\'|"]#Si', $css[0][$key], $cssMedia ) ) {
  828. $cssMedia = $cssMedia[1];
  829. } else {
  830. $cssMedia = '';
  831. }
  832. if ( !JFile::exists($filenamesource) ) {
  833. $cssparser = new cssparser('#jfusionframeless');
  834. $cssparser->setUrl($data->integratedURL);
  835. $cssparser->ParseStr($values);
  836. $content = $cssparser->GetCSS();
  837. JFile::write($filenamesource, $content);
  838. }
  839. if ( JFile::exists($filenamesource) ) {
  840. $document->addStyleSheet($urlpath.'infile/'.$filename,'text/css',$cssMedia);
  841. }
  842. }
  843. $html = preg_replace ( '#<style.*?type=[\'|"]text/css[\'|"].*?>(.*?)</style>#Sims', '', $html );
  844. }
  845. }
  846. }
  847. /**
  848. * Parsers the buffer recieved from getBuffer into header and body
  849. * @param $data
  850. */
  851. function parseBuffer(&$data) {
  852. $pattern = '#<head[^>]*>(.*?)<\/head>.*?<body([^>]*)>(.*)<\/body>#si';
  853. $temp = array();
  854. preg_match($pattern, $data->buffer, $temp);
  855. if(!empty($temp[1])) $data->header = $temp[1];
  856. if(!empty($temp[3])) $data->body = $temp[3];
  857. $pattern = '#onload=["]([^"]*)#si';
  858. if(!empty($temp[2])){
  859. if(preg_match($pattern, $temp[2], $temp)){
  860. $js = '<script language="JavaScript" type="text/javascript">
  861. if(window.addEventListener) { // Standard
  862. window.addEventListener(\'load\', function(){'.$temp[1].'}, false);
  863. } else if(window.attachEvent) { // IE
  864. window.attachEvent(\'onload\', function(){'.$temp[1].'});
  865. }
  866. </script>';
  867. $data->header .= $js;
  868. }
  869. }
  870. unset($temp);
  871. }
  872. /**
  873. * Parsers the buffer recieved from getBuffer into header and body
  874. *
  875. * @return array array with calender events
  876. */
  877. function getCalender() {
  878. return array();
  879. }
  880. }