/administrator/components/com_jfusion/models/model.abstractpublic.php
PHP | 985 lines | 632 code | 105 blank | 248 comment | 97 complexity | 9e5e8aac09158b8e74d4a7dbd0b186b5 MD5 | raw file
Possible License(s): Apache-2.0
- <?php
-
- /**
- * @package JFusion
- * @subpackage Models
- * @author JFusion development team
- * @copyright Copyright (C) 2008 JFusion. All rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
- */
-
- // no direct access
- defined('_JEXEC' ) or die('Restricted access' );
-
- /**
- * Abstract interface for all JFusion functions that are accessed through the Joomla front-end
- * @package JFusion
- */
- class JFusionPublic{
- /**
- * returns the name of this JFusion plugin
- * @return string name of current JFusion plugin
- */
- function getJname()
- {
- return '';
- }
-
- /**
- * Returns the registration URL for the integrated software
- * @return string registration URL
- */
- function getRegistrationURL()
- {
- return '';
- }
-
- /**
- * Returns the lost password URL for the integrated software
- * @return string lost password URL
- */
- function getLostPasswordURL()
- {
- return '';
- }
-
- /**
- * Returns the lost username URL for the integrated software
- * @return string lost username URL
- */
- function getLostUsernameURL()
- {
- return '';
- }
-
- /**
- * Returns Array of stdClass title / url
- * @return object Db columns assigned to title and url links for pathway
- */
- function getPathWay()
- {
- $path = new stdClass();
- $path->title = '';
- $path->url = '';
- $pathway[] = $path;
- return null;
- }
-
- /**
- * Returns the URL to a userprofile of the integrated software
- * @param integer $uid userid
- * @return string URL
- */
- function getProfileURL($uid)
- {
- return '';
- }
-
- /**
- * Retrieves the source path to the user's avatar
- * @param $uid software's user id
- * @return string with source path to users avatar
- */
- function getAvatar($uid)
- {
- return 0;
- }
-
- /**
- * Returns the URL to the view all private messages URL of the integrated software
- * @return string URL
- */
- function getPrivateMessageURL()
- {
- return '';
- }
-
- /**
- * Returns the URL to a view new private messages URL of the integrated software
- * @return string URL
- */
- function getViewNewMessagesURL()
- {
- return '';
- }
-
- /**
- * Returns the URL to a get private messages URL of the integrated software
- * @return string URL
- */
- function getPrivateMessageCounts($puser_id)
- {
- return 0;
- }
-
- /**
- * Prepares text for various areas
- *
- * @param string &$text Text to be modified
- * @param string $for (optional) Determines how the text should be prepared.
- * Options for $for as passed in by JFusion's plugins and modules are:
- * joomla (to be displayed in an article; used by discussion bot)
- * forum (to be published in a thread or post; used by discussion bot)
- * activity (displayed in activity module; used by the activity module)
- * search (displayed as search results; used by search plugin)
- * @param object $params (optional) Joomla parameter object passed in by JFusion's module/plugin
- * @param object $object (optional) Object with information for the specific element the text is from
- *
- * @return array $status Information passed back to calling script such as limit_applied
- */
- function prepareText(&$text, $for = '', $params = '', $object = '')
- {
- $status = array();
- if ($for == 'forum') {
- //first thing is to remove all joomla plugins
- preg_match_all('/\{(.*)\}/U', $text, $matches);
- //find each thread by the id
- foreach ($matches[1] AS $plugin) {
- //replace plugin with nothing
- $text = str_replace('{' . $plugin . '}', "", $text);
- }
- } elseif ($for == 'joomla' || ($for == 'activity' && $params->get('parse_text') == 'html')) {
- $options = array();
- if (!empty($params) && $params->get('character_limit', false)) {
- $status['limit_applied'] = 1;
- $options['character_limit'] = $params->get('character_limit');
- }
- JFusionFunction::parseCode($text, 'html', $options);
- } elseif ($for == 'search') {
- JFusionFunction::parseCode($text, 'plaintext');
- } elseif ($for == 'activity') {
- if ($params->get('parse_text') == 'plaintext') {
- $options = array();
- $options['plaintext_line_breaks'] = 'space';
- if ($params->get('character_limit')) {
- $status['limit_applied'] = 1;
- $options['character_limit'] = $params->get('character_limit');
- }
- JFusionFunction::parseCode($text, 'plaintext', $options);
- }
- }
- return $status;
- }
-
- /**
- * Parses custom BBCode defined in $this->prepareText() and called by the nbbc parser via JFusionFunction::parseCode()
- *
- * @return bbcode converted to html
- */
- function parseCustomBBCode ($bbcode, $action, $name, $default, $params, $content)
- {
- if ($action == 1) {
- return true;
- }
-
- $return = $content;
- switch ($name) {
- case 'size':
- $return = "<span style=\"font-size:$default\">$content</span>";
- break;
- case 'glow':
- $temp = explode(',', $default);
- $color = (!empty($temp[0])) ? $temp[0] : 'red';
- $return = "<span style=\"background-color:$color\">$content</span>";
- break;
- case 'shadow':
- $temp = explode(',', $default);
- $color = (!empty($temp[0])) ? $temp[0] : '#6374AB';
- $dir = (!empty($temp[1])) ? $temp[1] : 'left';
- $x = ($dir == 'left') ? '-0.2em' : '0.2em';
- $return = "<span style=\"text-shadow: $colo $x 0.1em 0.2em;\">$content</span>";
- break;
- case 'move':
- $return = "<marquee>$content</marquee>";
- break;
- case 'pre':
- $return = "<pre>$content</pre>";
- break;
- case 'hr':
- return '<hr>';
- break;
- case 'flash':
- $temp = explode(',', $default);
- $width = (!empty($temp[0])) ? $temp[0] : '200';
- $height = (!empty($temp[1])) ? $temp[1] : '200';
- $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>";
- break;
- case 'ftp':
- if (empty($default)) {
- $default = $content;
- }
- $return = "<a href='$content'>$default</a>";
- break;
- case 'table':
- $return = "<table>$content</table>";
- break;
- case 'tr':
- $return = "<tr>$content</tr>";
- break;
- case 'td':
- $return = "<td>$content</td>";
- break;
- case 'tt';
- $return = "<tt>$content</tt>";
- break;
- case 'o':
- case 'O':
- case '0':
- $return = "<li type='circle'>$content</li>";
- break;
- case '*':
- case '@':
- $return = "<li type='disc'>$content</li>";
- break;
- case '+':
- case 'x':
- case '#':
- $return = "<li type='square'>$content</li>";
- break;
- case 'abbr':
- if (empty($default)) {
- $default = $content;
- }
- $return = "<abbr title='$default'>$content</abbr>";
- break;
- case 'anchor':
- if (!empty($default)) {
- $return = "<span id='$default'>$content</span>";
- } else {
- $return = $content;
- }
- break;
- case 'black':
- case 'blue':
- case 'green':
- case 'red':
- case 'white':
- $return = "<span style='color: $name;'>$content</span>";
- break;
- case 'iurl':
- if (empty($default)) {
- $default = $content;
- }
- $return = "<a href='" . htmlspecialchars($default) . "' class='bbcode_url' target='_self'>$content</a>";
- break;
- case 'html':
- case 'nobbc':
- case 'php':
- $return = $content;
- break;
- case 'ltr':
- $return = "<div style='text-align: left;' dir='$name'>$content</div>";
- break;
- case 'rtl':
- $return = "<div style='text-align: right;' dir='$name'>$content</div>";
- break;
- case 'me':
- $return = "<div style='color: red;'>* $default $content</div>";
- break;
- case 'time':
- $return = date("Y-m-d H:i", $content);
- break;
- default:
- break;
- }
- return $return;
- }
-
- /************************************************
- * Functions For JFusion Search Plugin
- ***********************************************/
-
- /**
- * Retrieves the search results to be displayed. Placed here so that plugins that do not use the database can retrieve and return results
- * @param $text string text to be searched
- * @param $phrase string how the search should be performed exact, all, or any
- * @param $pluginParam custom plugin parameters in search.xml
- * @param $itemid what menu item to use when creating the URL
- * @return array of results as objects
- * Each result should include:
- * $result->title = title of the post/article
- * $result->section = (optional) section of the post/article (shows underneath the title; example is Forum Name / Thread Name)
- * $result->text = text body of the post/article
- * $result->href = link to the content (without this, joomla will not display a title)
- * $result->browsernav = 1 opens link in a new window, 2 opens in the same window
- * $result->created = (optional) date when the content was created
- *
- * @param string &$text string text to be searched
- * @param string &$phrase string how the search should be performed exact, all, or any
- * @param object &$pluginParam custom plugin parameters in search.xml
- * @param int $itemid what menu item to use when creating the URL
- * @param string $ordering ordering sent by Joomla: null, oldest, popular, category, alpha, or newest
- *
- * @return array of results as objects
- */
- function getSearchResults(&$text, &$phrase, &$pluginParam, $itemid, $ordering)
- {
- //initialize plugin database
- $db = & JFusionFactory::getDatabase($this->getJname());
- //get the query used to search
- $query = $this->getSearchQuery($pluginParam);
-
- //assign specific table colums to title and text
- $columns = $this->getSearchQueryColumns();
-
- //build the query
- if($phrase == 'exact') {
- $where = "((LOWER({$columns->title}) LIKE '%$text%') OR (LOWER({$columns->text}) like '%$text%'))";
- } else {
- $words = explode (' ', $text);
- $wheres = array();
- foreach($words as $word) {
- $wheres[] = "((LOWER({$columns->title}) LIKE '%$word%') OR (LOWER({$columns->text}) like '%$word%'))";
- }
-
- if($phrase == 'all') $separator = "AND";
- else $separator = "OR";
-
- $where = '(' . implode ( ") $separator (", $wheres) . ')';
- }
-
- //pass the where clause into the plugin in case it wants to add something
- $this->getSearchCriteria($where, $pluginParam, $ordering);
- $query .= " WHERE $where";
-
- //add a limiter if set
- $limit = $pluginParam->get('search_limit','');
- if(!empty($limit)) {
- $db->setQuery($query,0,$limit);
- } else {
- $db->setQuery($query);
- }
-
- $results = $db->loadObjectList();
-
- //pass results back to the plugin in case they need to be filtered
- $this->filterSearchResults($results, $pluginParam);
-
- //load the results
- if(is_array($results)) {
- foreach($results as $result) {
- //add a link
- $href = JFusionFunction::routeURL($this->getSearchResultLink($result), $itemid, $this->getJname(), false);
- $result->href = $href;
- //open link in same window
- $result->browsernav = 2;
- //clean up the text such as removing bbcode, etc
- $this->prepareText($result->text, 'search', $pluginParam, $result);
- $this->prepareText($result->title, 'search', $pluginParam, $result);
- $this->prepareText($result->section, 'search', $pluginParam, $result);
- }
- }
-
- return $results;
- }
-
- /**
- * Assigns specific db columns to title and text of content retrieved
- * @return object Db columns assigned to title and text of content retrieved
- */
- function getSearchQueryColumns()
- {
- $columns = new stdClass();
- $columns->title = '';
- $columns->text = '';
- return $columns;
- }
-
- /**
- * Generates SQL query for the search plugin that does not include where, limit, or order by
- * @param object &$pluginParam custom plugin parameters in search.xml
- * @return string Returns query string
- */
- function getSearchQuery(&$pluginParam)
- {
- return '';
- }
-
- /**
- * Add on a plugin specific clause;
- * @param $where reference to where clause already generated by search bot; add on plugin specific criteria
- * @param object &$pluginParam custom plugin parameters in search.xml
- * @param string $ordering ordering sent by Joomla: null, oldest, popular, category, alpha, or newest
- * @return string Returns search criteria
- */
- function getSearchCriteria(&$where, &$pluginParam, $ordering)
- {
-
- }
-
- /**
- * Filter out results from the search ie forums that a user does not have permission to
- * @param object &$pluginParam custom plugin parameters in search.xml
- * @param $results object list of search query results
- */
- function filterSearchResults(&$results, &$pluginParam)
- {
-
- }
-
- /**
- * Returns the URL for a post
- * @param $vars mixed
- * @return string with URL
- */
- function getSearchResultLink($vars)
- {
- return '';
- }
-
- /************************************************
- * Functions For JFusion Who's Online Module
- ***********************************************/
-
- /**
- * Returns a query to find online users
- * Make sure columns are named as userid, username, username_clean (if applicable), name (of user), and email
- * @param $limit integer to use as a limiter for the number of results returned
- * @param $usergroups optional array or string of group ids
- */
- function getOnlineUserQuery($limit, $usergroups = "")
- {
- return '';
- }
-
- /**
- * Returns number of guests
- * @return int
- */
- function getNumberOnlineGuests()
- {
- return 0;
- }
-
- /**
- * Returns number of logged in users
- * @param $usergrups optonal array or string of usergroups for filtering purposes
- * @param $total optional boolean to show a count of all members or only those belonging to set usergroups
- * @return int
- */
- function getNumberOnlineMembers($usergroups = '', $total = 1)
- {
- return 0;
- }
-
- /**
- * Set the language from Joomla to the integrated software
- * @todo - To implement after the release RC 1.1.2
- *
- * @param object $userinfo - it can be null if the user is not logged for example.
- */
- function setLanguageFrontEnd($userinfo = null){
-
- $status = array();
- $status['error'] = '';
- $status['debug'] = JText::_( 'METHOD_NOT_IMPLEMENTED' );
-
- return $status;
- }
-
- /************************************************
- * Functions For JFusion Activity Module
- ***********************************************/
-
- /**
- * Returns the an array with SQL statements used by the activity module
- * @return array
- */
- function getActivityQuery($usedforums, $result_order, $result_limit)
- {
- return 0;
- }
-
- /**
- * Filter forums from a set of results sent in / useful if the plugin needs to restrict the forums visible to a user
- * @param $results set of results from query
- * @param $limit int limit results parameter as set in the module's params; used for plugins that cannot limit using a query limiter
- */
- function filterActivityResults(&$results, $limit=0)
- {
-
- }
-
- /*
- * Frameless Abscract functions
- */
-
- /**
- * gets the visual html output from the plugin
- */
- function getBuffer(&$data)
- {
- require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.curlframeless.php');
-
- $status = JFusionCurlFrameless::display($data);
- if ( isset($data->location) ) {
- $location = str_replace($data->integratedURL,'',$data->location);
- $location = $this->fixUrl($location,$data->baseURL,$data->fullURL,$data->integratedURL,$data->jroute);
- $mainframe = & JFactory::getApplication();
- $mainframe->redirect($location);
- }
- if ( isset($status['error']) ) {
- foreach ( $status['error'] as $key => $value ) {
- JError::raiseWarning(500, $value);
- }
- }
- }
-
- /**
- * function that parses the HTML body and fixes up URLs and form actions
- * @param string the HTML body output generated by getBuffer()
- * @param string $baseURL the base joomla URL to add variables to
- * @param string $fullURL the full URL to the current page
- * @param string $integratedURL the URL to the integrated software
- * @return object userinfo Object containing the user information
- */
- function parseBody(&$data)
- {
- $regex_body = array();
- $replace_body = array();
- $params = JFusionFactory::getParams($this->getJname());
-
-
- // $regex_body[] = '#(href|action)=["|\']'.$data->integratedURL.'(.*?)["|\']#mS';
- // $replace_body[] = '$1="/$2"';
-
- // $regex_body[] = '#(href|action)=["|\'](?!\w{0,10}://|\w{0,10}:)(.\S*?)["|\']#mSie';
- // $replace_body[] = '\'$1="\'.$this->fixUrl("$2","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'").\'"\'';
-
-
- if (substr($data->baseURL, -1) != '/'){
- $urlMode = 1;
- } else if ($data->jroute==1) {
- $urlMode = 2;
- } else {
- $urlMode = 3;
- }
-
- //parse anchors
- if(!empty($data->parse_anchors)) {
- $regex_body[] = '#href="\#(.*?)"#mS';
- $replace_body[] = 'href="'.$data->fullURL.'#$1"';
- }
-
- //parse absolute URLS
- if(!empty($data->parse_abs_path)) {
- $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $data->integratedURL );
- $path = preg_replace('#//+#','/',"/$path/");
-
- $regex_body[] = '#(action="|href="|src="|background="|url\(\'?)'.$path.'(.*?)("|\'?\))#mS';
- $replace_body[] = '$1'.$data->integratedURL.'$2$3';
-
- switch ($urlMode) {
- case 1:
- case 2:
- $regex_body[] = '#href="'.$path.'(.*?)"#me';
- $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
- break;
- case 3:
- $regex_body[] = '#href="'.$path.'(.*?)"#mS';
- $replace_body[] = 'href="'.$data->baseURL.'$1"';
- break;
- }
- }
-
- //parse relative URLS
- if(!empty($data->parse_rel_url)) {
- switch ($urlMode) {
- case 1:
- case 2:
- $regex_body[] = '#href="[./|/](.*?)"#me';
- $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
- $regex_body[] = '#href="(?!\w{0,10}://|\w{0,10}:)(.*?)"#me';
- $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
- break;
- case 3:
- $regex_body[] = '#href="[./| /](.*?)"#mS';
- $replace_body[] = 'href="'.$data->baseURL.'$1"';
- $regex_body[] = '#href="(?!\w{0,10}://|\w{0,10}:)(.*?)"#mS';
- $replace_body[] = 'href="'.$data->baseURL.'$1"';
- break;
- }
- }
-
- //parse absolute URLS
- if(!empty($data->parse_abs_url)) {
- switch ($urlMode) {
- case 1:
- case 2:
- $regex_body[] = '#href="'.$data->integratedURL.'(.*?)"#me';
- $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'","'.$data->integratedURL.'","'.$data->jroute.'").\'"\'';
- break;
- case 3:
- $regex_body[] = '#href="'.$data->integratedURL.'(.*?)"#mS';
- $replace_body[] = 'href="'.$data->baseURL.'$1"';
- break;
- }
- }
-
- //convert relative links from images into absolute links
- if(!empty($data->parse_rel_img)) {
- $regex_body[] = '#(src="|background="|url\()[./|/](.*?)("|\))#mS';
- $replace_body[] = '$1'.$data->integratedURL.'$2$3';
- $regex_body[] = '#(src="|background="|url\()(?!\w{0,10}://|\w{0,10}:)(.*?)("|\))#mS';
- $replace_body[] = '$1'.$data->integratedURL.'$2$3';
- }
-
- //parse form actions
- if(!empty($data->parse_action)) {
- switch ($urlMode) {
- case 1:
- case 2:
- if (!empty($data->parse_abs_path)) {
- $regex_body[] = '#action="'.$path.'(.*?)"(.*?)>#me';
- $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
- }
- if (!empty($data->parse_abs_url)) {
- $regex_body[] = '#action="'.$data->integratedURL.'(.*?)"(.*?)>#me';
- $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
- }
- if (!empty($data->parse_rel_url)) {
- $regex_body[] = '#action="[./|/](.*?)"(.*?)>#me';
- $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'","'.$data->jroute.'")';
- }
- break;
- case 3:
- if (!empty($data->parse_abs_path)) {
- $regex_body[] = '#action="'.$path.'(.*?)"#mS';
- $replace_body[] = 'action="'.$data->baseURL.'$1"';
- }
- if (!empty($data->parse_abs_url)) {
- $regex_body[] = '#action="'.$data->integratedURL.'(.*?)"#mS';
- $replace_body[] = 'action="'.$data->baseURL.'$1"';
- }
- if (!empty($data->parse_rel_url)) {
- $regex_body[] = '#action="[./|/](.*?)"#mS';
- $replace_body[] = 'action="'.$data->baseURL.'$1"';
- }
- break;
- }
- }
-
- //parse relative popup links to full url links
- if(!empty($data->parse_popup)) {
- $regex_body[] = "#window\.open\('(?!\w{0,10}://)(.*?)'\)#mS";
- $replace_body[] = 'window.open(\''.$data->integratedURL.'$1\'';
- }
-
- $value = $data->bodymap;
- if(is_array($value)) {
- foreach ($value['value'] as $key => $val) {
- $regex = html_entity_decode($value['value'][$key]);
- $regex = rtrim($regex,';');
- $regex = eval("return '$regex';");
-
- $replace = html_entity_decode($value['name'][$key]);
- $replace = rtrim($replace,';');
- $replace = eval("return '$replace';");
-
- if ($regex && $replace) {
- $regex_body[] = $regex;
- $replace_body[] = $replace;
- }
- }
- }
- $data->body = preg_replace($regex_body, $replace_body, $data->body);
-
- if ( method_exists($this , '_parseBody') ) {
- $this->_parseBody($data);
- }
- }
-
- /**
- * function that parses the HTML header and fixes up URLs
- * @param string $buffer the output generated by getBuffer()
- * @param string $baseURL the base joomla URL to add variables to
- * @param string $fullURL the full URL to the current page
- * @param string $integratedURL the URL to the integrated software
- * @return object userinfo Object containing the user information
- */
- function parseHeader(&$data)
- {
- // Define our preg arrays
- $regex_header = array();
- $replace_header = array();
- $params = JFusionFactory::getParams($this->getJname());
-
- //convert relative links into absolute links
- $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $data->integratedURL );
- $path = preg_replace('#//+#','/',"/$path/");
-
- $regex_header[] = '#(href|src)=[\'|"]'.$path.'(.*?)[\'|"]#Si';
- $replace_header[] = '$1="'.$data->integratedURL.'$2"';
- $regex_header[] = '#(href|src)=[\'|"](./|/)(.*?)[\'|"]#iS';
- $replace_header[] = '$1="'.$data->integratedURL.'$3"';
- $regex_header[] = '#(href|src)=["|\'](?!\w{0,10}://)(.*?)["|\']#mSi';
- $replace_header[] = '$1="'.$data->integratedURL.'$2"';
- $regex_header[] = '#@import(.*?)[\'"]'.$path.'(.*?)[\'"]#Sis';
- $replace_header[] = '@import$1"'.$data->integratedURL.'$2"';
- $regex_header[] = '#@import(.*?)[\'"]/(.*?)[\'"]#Sis';
- $replace_header[] = '@import$1"'.$data->integratedURL.'$2"';
-
- //fix for URL redirects
- $parse_redirect = $params->get('parse_redirect');
- if(!empty($parse_redirect)) {
- $regex_header[] = '#<meta http-equiv=[\'|"]refresh[\'|"] content=[\'|"](.*?)[\'|"](.*?)>#meis';
- $replace_header[] = '$this->fixRedirect("$1","'.$data->baseURL.'","'.$data->integratedURL.'","'.$data->jroute.'")';
- }
-
- $value = $data->headermap;
-
- if(is_array($value)) {
- foreach ($value['value'] as $key => $val) {
- $regex = html_entity_decode($value['value'][$key]);
- $regex = rtrim($regex,';');
- $regex = eval("return '$regex';");
-
- $replace = html_entity_decode($value['name'][$key]);
- $replace = rtrim($replace,';');
- $replace = eval("return '$replace';");
-
- if ($regex && $replace) {
- $regex_header[] = $regex;
- $replace_header[] = $replace;
- }
- }
- }
- $data->header = preg_replace($regex_header, $replace_header, $data->header);
-
- if ( method_exists($this , '_parseHeader') ) {
- $this->_parseHeader($data);
- }
- }
-
- /**
- * extends JFusion's parseRoute function to reconstruct the SEF URL
- *
- * @param array $vars vars already parsed by JFusion's router.php file
- *
- */
- function parseRoute(&$vars)
- {
- }
-
- /**
- * extends JFusion's buildRoute function to build the SEF URL
- *
- * @param array &$segments query already prepared by JFusion's router.php file
- */
- function buildRoute(&$segments)
- {
- }
-
- function fixUrl($q='',$baseURL,$fullURL,$integratedURL,$jRoute)
- {
- if (substr($baseURL, -1) != '/') {
- //non sef URls
- $q = str_replace('?', '&', $q);
- $url = $baseURL . '&jfile=' .$q;
- } else if ($jRoute==1) {
- $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
- } else {
- //we can just append both variables
- $url = $baseURL . $q;
- }
-
- return $url;
- }
-
- function fixAction($url, $extra, $baseURL,$jRoute)
- {
- $url = htmlspecialchars_decode($url);
- $Itemid = JRequest::getInt('Itemid');
-
- //strip any leading dots
- if(substr($url,0,2)== './'){
- $url = substr($url,2);
- }
-
- if (substr($baseURL, -1) != '/'){
- //non-SEF mode
- $url_details = parse_url($url);
- $url_variables = array();
- if (isset($url_details['query'])) parse_str($url_details['query'], $url_variables);
- $jfile = basename($url_details['path']);
- //set the correct action and close the form tag
- $replacement = 'action="'.$baseURL . '"' . $extra . '>';
- $replacement .= '<input type="hidden" name="jfile" value="'. $jfile . '"/>';
- $replacement .= '<input type="hidden" name="Itemid" value="'.$Itemid . '"/>';
- $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
- } else if ($jRoute==1) {
- //extensive SEF parsing was selected
- $url = JFusionFunction::routeURL($url, $Itemid);
- $replacement = 'action="'.$url . '"' . $extra . '>';
- return $replacement;
- } else {
- //simple SEF mode
- $url_details = parse_url($url);
- $url_variables = array();
- if (isset($url_details['query'])) parse_str($url_details['query'], $url_variables);
- $jfile = basename($url_details['path']);
- $replacement = 'action="'.$baseURL . $jfile.'"' . $extra . '>';
- }
- unset($url_variables['option'],$url_variables['jfile'],$url_variables['Itemid']);
-
- //add any other variables
- if(is_array($url_variables)){
- foreach ($url_variables as $key => $value){
- $replacement .= '<input type="hidden" name="'. $key .'" value="'.$value . '"/>';
- }
- }
- return $replacement;
- }
-
- function fixRedirect($url, $baseURL, $integratedURL,$jRoute)
- {
- //split up the timeout from url
- preg_match( '#(.*?)url=(.*?)\z#i' , $url ,$parts );
- $timeout = $parts[1];
- $url = $parts[2];
-
- $path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $integratedURL );
- $path = preg_replace('#//+#','/',"/$path/");
-
- $regex_url[] = '#'.$integratedURL.'(.*?)#mS';
- $replace_url[] = '$1';
- $regex_url[] = '#'.$path.'(.*?)#mS';
- $replace_url[] = '$1';
-
- $url = preg_replace($regex_url, $replace_url, $url);
-
- $url = $this->fixUrl($url,$baseURL,$baseURL,$integratedURL,$jRoute);
-
- $return = '<meta http-equiv="refresh" content="'.$timeout.'url=' . $url .'">';
- return $return;
- }
-
- /**
- * function that parses the HTML and fix the css
- * @param string $html data to parse
- * @param string $infile_only parse only infile (body)
- */
- function parseCSS(&$data,&$html,$infile_only=false)
- {
- $jname = $this->getJname();
- $param =& JFusionFactory::getParams ( $this->getJname() );
-
- if (empty($jname)) {
- $jname = JRequest::getVar ( 'Itemid' );
- }
-
- $document = JFactory::getDocument();
-
- $sourcepath = JPATH_SITE . DS . 'components' . DS . 'com_jfusion' . DS . 'css' . DS .$jname . DS;
- $urlpath = 'components/com_jfusion/css/'.$jname.'/';
-
- jimport('joomla.filesystem.file');
- jimport('joomla.filesystem.folder');
-
- JFolder::create($sourcepath.'infile');
- if (!$infile_only) {
- //Outputs: apearpearle pear
- $urlPattern = array('http://', 'https://', '.css', '\\', '/', '|', '*', ':', ';', '?', '"', '<', '>', '=', '&');
- $urlReplace = array('', '', '', '', '-', '', '', '', '', '', '', '', '', ',', '_');
- if ($data->parse_css) {
- if (preg_match_all( '#<link(.*?type=[\'|"]text\/css[\'|"][^>]*)>#Si', $html, $css )) {
-
- $regex_header = array ();
- $replace_header = array ();
- require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'parsers' . DS . 'css.php');
-
- jimport('joomla.filesystem.file');
- foreach ($css[1] as $key => $values) {
- if( preg_match( '#href=[\'|"](.*?)[\'|"]#Si', $values, $cssUrl )) {
- $cssUrlRaw = $cssUrl[1];
- $cssUrl = urldecode(htmlspecialchars_decode($cssUrl[1]));
-
- if ( preg_match( '#media=[\'|"](.*?)[\'|"]#Si', $values, $cssMedia ) ) {
- $cssMedia = $cssMedia[1];
- } else {
- $cssMedia = '';
- }
- $filename = str_replace($urlPattern, $urlReplace, $cssUrl).'.css';
- $filenamesource = $sourcepath.$filename;
-
- if ( !JFile::exists($filenamesource) ) {
- $cssparser = new cssparser('#jfusionframeless');
- $result = $cssparser->ParseUrl($cssUrlRaw);
- if ($result !== false ) {
- $content = $cssparser->GetCSS();
- JFile::write($filenamesource, $content);
- }
- }
-
- if ( JFile::exists($filenamesource) ) {
- $html = str_replace($cssUrlRaw , $urlpath.$filename , $html );
- }
- }
- }
- }
- }
- }
- if ($data->parse_infile_css) {
- if (preg_match_all( '#<style.*?type=[\'|"]text/css[\'|"].*?>(.*?)</style>#Sims', $html, $css )) {
- require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'parsers' . DS . 'css.php');
- foreach ($css[1] as $key => $values) {
- $filename = md5($values).'.css';
- $filenamesource = $sourcepath.'infile'.DS.$filename;
-
- if ( preg_match( '#media=[\'|"](.*?)[\'|"]#Si', $css[0][$key], $cssMedia ) ) {
- $cssMedia = $cssMedia[1];
- } else {
- $cssMedia = '';
- }
-
- if ( !JFile::exists($filenamesource) ) {
- $cssparser = new cssparser('#jfusionframeless');
- $cssparser->setUrl($data->integratedURL);
- $cssparser->ParseStr($values);
- $content = $cssparser->GetCSS();
- JFile::write($filenamesource, $content);
- }
- if ( JFile::exists($filenamesource) ) {
- $document->addStyleSheet($urlpath.'infile/'.$filename,'text/css',$cssMedia);
- }
- }
- $html = preg_replace ( '#<style.*?type=[\'|"]text/css[\'|"].*?>(.*?)</style>#Sims', '', $html );
- }
- }
- }
- /**
- * Parsers the buffer recieved from getBuffer into header and body
- * @param $data
- */
- function parseBuffer(&$data) {
- $pattern = '#<head[^>]*>(.*?)<\/head>.*?<body([^>]*)>(.*)<\/body>#si';
- $temp = array();
-
- preg_match($pattern, $data->buffer, $temp);
- if(!empty($temp[1])) $data->header = $temp[1];
- if(!empty($temp[3])) $data->body = $temp[3];
-
- $pattern = '#onload=["]([^"]*)#si';
- if(!empty($temp[2])){
- if(preg_match($pattern, $temp[2], $temp)){
- $js = '<script language="JavaScript" type="text/javascript">
- if(window.addEventListener) { // Standard
- window.addEventListener(\'load\', function(){'.$temp[1].'}, false);
- } else if(window.attachEvent) { // IE
- window.attachEvent(\'onload\', function(){'.$temp[1].'});
- }
- </script>';
- $data->header .= $js;
- }
- }
- unset($temp);
- }
- /**
- * Parsers the buffer recieved from getBuffer into header and body
- *
- * @return array array with calender events
- */
- function getCalender() {
- return array();
- }
- }