Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 18.12 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7. * @package JFusion
  8.  
  9. * @subpackage Models
  10.  
  11. * @author JFusion development team
  12.  
  13. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  14.  
  15. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  16.  
  17. */
  18.  
  19.  
  20.  
  21. // no direct access
  22.  
  23. defined('_JEXEC' ) or die('Restricted access' );
  24.  
  25.  
  26.  
  27. /**
  28.  
  29. * Class for general JFusion functions
  30.  
  31. * @package JFusion
  32.  
  33. */
  34.  
  35.  
  36.  
  37. class JFusionFunction{
  38.  
  39.  
  40.  
  41.     /**
  42.  
  43. * Returns the JFusion plugin name of the software that is currently the master of user management
  44.  
  45. * @param string $jname Name of master JFusion plugin
  46.  
  47. */
  48.  
  49.  
  50.  
  51.     function getMaster()
  52.  
  53.     {
  54.  
  55.         $db = & JFactory::getDBO();
  56.  
  57.         $query = 'SELECT * from #__jfusion WHERE master = 1 and status = 1';
  58.  
  59.         $db->setQuery($query );
  60.  
  61.         $jname = $db->loadObject();
  62.  
  63.  
  64.  
  65.         if ($jname) {
  66.  
  67.             return $jname;
  68.  
  69.         }
  70.  
  71.     }
  72.  
  73.  
  74.  
  75.     /**
  76.  
  77. * Returns the JFusion plugin name of the software that are currently the slaves of user management
  78.  
  79. * @param string $jname Name of master JFusion plugin
  80.  
  81. */
  82.  
  83.  
  84.  
  85.     function getSlaves()
  86.  
  87.     {
  88.  
  89.         //find the first forum that is enabled
  90.  
  91.         $db = & JFactory::getDBO();
  92.  
  93.         $query = 'SELECT * from #__jfusion WHERE slave = 1 and status = 1';
  94.  
  95.         $db->setQuery($query );
  96.  
  97.         $jname = $db->loadObjectList();
  98.  
  99.         return $jname;
  100.  
  101.  
  102.  
  103.     }
  104.  
  105.  
  106.  
  107.     /**
  108.  
  109. * Returns the JFusion plugin name of the software that is currently the slave of user management, minus the joomla_int plugin
  110.  
  111. * @param array $jname Array list of slave JFusion plugin names
  112.  
  113. */
  114.  
  115.  
  116.  
  117.     function getPlugins()
  118.  
  119.     {
  120.  
  121.         //find the first forum that is enabled
  122.  
  123.         $db = & JFactory::getDBO();
  124.  
  125.         $query = 'SELECT * from #__jfusion WHERE (slave = 1 AND status = 1 AND name NOT LIKE \'joomla_int\')';
  126.  
  127.         $db->setQuery($query );
  128.  
  129.         $list = $db->loadObjectList();
  130.  
  131.         return $list;
  132.  
  133.     }
  134.  
  135.  
  136.  
  137.     /**
  138.  
  139. * Returns the parameters of a specific JFusion integration
  140.  
  141. * @param string $jname name of the JFusion plugin used
  142.  
  143. * @return object Joomla parameters object
  144.  
  145. */
  146.  
  147.  
  148.  
  149.     function &getParameters($jname)
  150.  
  151.     {
  152.  
  153.         //get the current parameters from the jfusion table
  154.  
  155.         $db = & JFactory::getDBO();
  156.  
  157.         $query = 'SELECT params from #__jfusion WHERE name = ' . $db->quote($jname);
  158.  
  159.         $db->setQuery($query );
  160.  
  161.         $serialized = $db->loadResult();
  162.  
  163.  
  164.  
  165.         //get the parameters from the XML file
  166.  
  167.         $file = JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'plugins'.DS. $jname . DS.'jfusion.xml';
  168.  
  169.  
  170.  
  171.         $parametersInstance = new JParameter('', $file );
  172.  
  173.  
  174.  
  175.         //apply the stored valued
  176.  
  177.         if ($serialized) {
  178.  
  179.             $params = unserialize(base64_decode($serialized));
  180.  
  181.  
  182.  
  183.             if (is_array($params)) {
  184.  
  185.                 foreach($params as $key => $value) {
  186.  
  187.                     $parametersInstance->set($key, $value );
  188.  
  189.                 }
  190.  
  191.             }
  192.  
  193.         }
  194.  
  195.  
  196.  
  197.         if (!is_object($parametersInstance)) {
  198.  
  199.             JError::raiseError(500, JText::_('NO_FORUM_PARAMETERS'));
  200.  
  201.         }
  202.  
  203.  
  204.  
  205.         return $parametersInstance;
  206.  
  207.     }
  208.  
  209.  
  210.  
  211.     /**
  212.  
  213. * Saves the posted JFusion component variables
  214.  
  215. * @param string $jname name of the JFusion plugin used
  216.  
  217. * @param array $post Array of JFusion plugin parameters posted to the JFusion component
  218.  
  219. * @return true|false returns true if succesful and false if an error occurred
  220.  
  221. */
  222.  
  223.  
  224.  
  225.     function saveParameters($jname, $post)
  226.  
  227.     {
  228.  
  229.         $mergedpost = array_merge((array) JFusionFunction::getparameters($jname)->_registry['_default']['data'],$post);
  230.  
  231.         //serialize the $post to allow storage in a SQL field
  232.  
  233.         $serialized = base64_encode(serialize($mergedpost));
  234.  
  235.  
  236.  
  237.         //set the current parameters in the jfusion table
  238.  
  239.         $db = & JFactory::getDBO();
  240.  
  241.         $query = 'UPDATE #__jfusion SET params = ' . $db->quote($serialized) .' WHERE name = ' . $db->quote($jname);
  242.  
  243.         $db->setQuery($query );
  244.  
  245.  
  246.  
  247.         if (!$db->query()) {
  248.  
  249.             //there was an error saving the parameters
  250.  
  251.             JError::raiseWarning(0,$db->stderr());
  252.  
  253.             $result = false;
  254.  
  255.             return $result;
  256.  
  257.         }
  258.  
  259.  
  260.  
  261.         $result = true;
  262.  
  263.         return $result;
  264.  
  265.     }
  266.  
  267.  
  268.  
  269.     /**
  270.  
  271. * Checks to see if the JFusion plugins are installed and enabled
  272.  
  273. */
  274.  
  275.     function checkPlugin()
  276.  
  277.     {
  278.  
  279.         $userPlugin = true;
  280.  
  281.         $authPlugin = true;
  282.  
  283.         if (!JFusionFunction::isPluginInstalled('jfusion','authentication', false)) {
  284.  
  285.             JError::raiseWarning(0,JText::_('FUSION_MISSING_AUTH'));
  286.  
  287.             $authPlugin = false;
  288.  
  289.         }
  290.  
  291.  
  292.  
  293.         if (!JFusionFunction::isPluginInstalled('jfusion','user', false)) {
  294.  
  295.             JError::raiseWarning(0,JText::_('FUSION_MISSING_USER'));
  296.  
  297.             $userPlugin = false;
  298.  
  299.         }
  300.  
  301.  
  302.  
  303.         if ($authPlugin && $userPlugin) {
  304.  
  305.             $jAuth = JFusionFunction::isPluginInstalled('jfusion','user',true);
  306.  
  307.             $jUser = JFusionFunction::isPluginInstalled('jfusion','authentication',true);
  308.  
  309.             if (!$jAuth) {
  310.  
  311.                 JError::raiseNotice(0,JText::_('FUSION_READY_TO_USE_AUTH'));
  312.  
  313.             }
  314.  
  315.             if (!$jUser) {
  316.  
  317.                 JError::raiseNotice(0,JText::_('FUSION_READY_TO_USE_USER'));
  318.  
  319.             }
  320.  
  321.         }
  322.  
  323.     }
  324.  
  325.  
  326.  
  327.  
  328.  
  329.     /**
  330.  
  331. * Checks to see if the configuration of a Jfusion plugin is valid and stores the result in the JFusion table
  332.  
  333. * @param string $jname name of the JFusion plugin used
  334.  
  335. */
  336.  
  337.  
  338.  
  339.     /**
  340.  
  341. * Tests if a plugin is installed with the specified name, where folder is the type (e.g. user)
  342.  
  343. * @param string $element element name of the plugin
  344.  
  345. * @param string $folder folder name of the plugin
  346.  
  347. * @param integer $testPublished Variable to determine if the function should test to see if the plugin is published
  348.  
  349. * @return true|false returns true if succesful and false if an error occurred
  350.  
  351. */
  352.  
  353.     function isPluginInstalled($element,$folder, $testPublished)
  354.  
  355.     {
  356.  
  357.         $db =& JFactory::getDBO();
  358.  
  359.         $query = 'SELECT published FROM #__plugins WHERE element=' . $db->quote($element) . ' AND folder=' . $db->quote($folder);
  360.  
  361.         $db->setQuery($query);
  362.  
  363.         $result = $db->loadObject();
  364.  
  365.         if ($result) {
  366.  
  367.             if ($testPublished) {
  368.  
  369.                 return($result->published == 1);
  370.  
  371.             } else {
  372.  
  373.                     $result = true;
  374.  
  375.                 return $result;
  376.  
  377.             }
  378.  
  379.         } else {
  380.  
  381.             $result = false;
  382.  
  383.             return $result;
  384.  
  385.         }
  386.  
  387.     }
  388.  
  389.  
  390.  
  391.     /**
  392.  
  393. * Acquires a database connection to the database of the software integrated by JFusion
  394.  
  395. * @param string $jname name of the JFusion plugin used
  396.  
  397. * @return object JDatabase
  398.  
  399. */
  400.  
  401.     function &getDatabase($jname)
  402.  
  403.     {
  404.  
  405.                 //check to see if joomla DB is requested
  406.  
  407.                 if ($jname == 'joomla_int'){
  408.  
  409.                 $db = & JFactory::getDBO();
  410.  
  411.                 return $db;
  412.  
  413.                 }
  414.  
  415.  
  416.  
  417.         //get the debug configuration setting
  418.  
  419.         $conf =& JFactory::getConfig();
  420.  
  421.         $debug = $conf->getValue('config.debug');
  422.  
  423.  
  424.  
  425.         //TODO see if we can delete these jimports below
  426.  
  427.         jimport('joomla.database.database');
  428.  
  429.         jimport('joomla.database.table' );
  430.  
  431.  
  432.  
  433.         //get config values
  434.  
  435.         $conf =& JFactory::getConfig();
  436.  
  437.         $params = JFusionFactory::getParams($jname);
  438.  
  439.  
  440.  
  441.         //prepare the data for creating a database connection
  442.  
  443.         $host = $params->get('database_host');
  444.  
  445.         $user = $params->get('database_user');
  446.  
  447.         $password = $params->get('database_password');
  448.  
  449.         $database = $params->get('database_name');
  450.  
  451.         $prefix = $params->get('database_prefix');
  452.  
  453.         $driver = $params->get('database_type');
  454.  
  455.         $debug = $conf->getValue('config.debug');
  456.  
  457.  
  458.  
  459.                 //added extra code to prevent error when $driver is incorrect
  460.  
  461.                 if ($driver != 'mysql' && $driver != 'mysqli') {
  462.  
  463.                         //invalid driver
  464.  
  465.             JError::raiseWarning(0, JText::_('INVALID_DRIVER'));
  466.  
  467.             $result = false;
  468.  
  469.             return $result;
  470.  
  471.                 }
  472.  
  473.  
  474.  
  475.         //create an options variable that contains all database connection variables
  476.  
  477.         $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );
  478.  
  479.  
  480.  
  481.         //create the actual connection
  482.  
  483.         $jfusion_database =& JDatabase::getInstance($options );
  484.  
  485.         if (!method_exists($jfusion_database,'Execute')){
  486.  
  487.             JError::raiseWarning(0, JText::_('NO_DATABASE'));
  488.  
  489.             $result = false;
  490.  
  491.             return $result;
  492.  
  493.         } else {
  494.  
  495.                 //add support for UTF8
  496.  
  497.             $jfusion_database->Execute('SET names \'utf8\'');
  498.  
  499.             //support debugging
  500.  
  501.                         $jfusion_database->debug($debug);
  502.  
  503.                 return $jfusion_database;
  504.  
  505.         }
  506.  
  507.  
  508.  
  509.     }
  510.  
  511.  
  512.  
  513.     /**
  514.  
  515. * Returns either the Joomla wrapper URL or the full URL directly to the forum
  516.  
  517. * @param string $url relative path to a webpage of the integrated software
  518.  
  519. * @param string $jname name of the JFusion plugin used
  520.  
  521. * @return string full URL to the filename passed to this function
  522.  
  523. */
  524.  
  525.  
  526.  
  527.     function createURL($url, $jname, $view, $itemid)
  528.  
  529.     {
  530.  
  531.         if(!empty($itemid)){
  532.  
  533.             //use the itemid only to identify plugin name and view type
  534.  
  535.             $base_url = 'index.php?option=com_jfusion&amp;Itemid=' . $itemid;
  536.  
  537.         } else {
  538.  
  539.             $base_url = 'index.php?option=com_jfusion&amp;view=' . $view . '&amp;jname=' . $jname;
  540.  
  541.         }
  542.  
  543.  
  544.  
  545.                 if ($view == 'direct') {
  546.  
  547.             $params = JFusionFactory::getParams($jname);
  548.  
  549.             $url = $params->get('source_url') . $url;
  550.  
  551.             return $url;
  552.  
  553.                 } elseif ($view == 'wrapper') {
  554.  
  555.                 //use base64_encode to encode the URL for passing.  But, base64_code uses / which throws off SEF urls.  Thus slashes
  556.  
  557.                 //must be translated into something base64_encode will not generate and something that will not get changed by Joomla or Apache.
  558.  
  559.             $url = $base_url . '&amp;wrap='. str_replace("/","_slash_",base64_encode($url));
  560.  
  561.             $url = JRoute::_($url);
  562.  
  563.             return $url;
  564.  
  565.         } elseif ($view == 'frameless'){
  566.  
  567.             //split the filename from the query
  568.  
  569.             $parts = explode('?', $url);
  570.  
  571.             if (isset($parts[1])) {
  572.  
  573.                 $base_url .= '&amp;jfile=' . $parts[0] . '&amp;' . $parts[1];
  574.  
  575.             } else {
  576.  
  577.                 $base_url .= '&amp;jfile=' . $parts[0];
  578.  
  579.             }
  580.  
  581.  
  582.  
  583.             $url = JRoute::_($base_url);
  584.  
  585.                 return $url;
  586.  
  587.         }
  588.  
  589.     }
  590.  
  591.  
  592.  
  593.     /**
  594.  
  595. * Updates the JFusion user lookup table during login
  596.  
  597. * @param object $userinfo object containing the userdata
  598.  
  599. * @param string $jname name of the JFusion plugin used
  600.  
  601. * @param string $joomla_id The Joomla ID of the user
  602.  
  603. */
  604.  
  605.  
  606.  
  607.     function updateLookup($userinfo, $jname, $joomla_id)
  608.  
  609.     {
  610.  
  611.  
  612.  
  613.         $db =& JFactory::getDBO();
  614.  
  615.         //prepare the variables
  616.  
  617.         $lookup = new stdClass;
  618.  
  619.         $lookup->userid = $userinfo->userid;
  620.  
  621.         $lookup->username = $userinfo->username;
  622.  
  623.         $lookup->jname = $jname;
  624.  
  625.         $lookup->id = $joomla_id;
  626.  
  627.  
  628.  
  629.  
  630.  
  631.         //insert the entry into the lookup table
  632.  
  633.         $db->insertObject('#__jfusion_users_plugin', $lookup, 'autoid' );
  634.  
  635.     }
  636.  
  637.  
  638.  
  639.     /**
  640.  
  641. * Returns the userinfo data for JFusion plugin based on the Joomla userid
  642.  
  643. * @param string $jname name of the JFusion plugin used
  644.  
  645. * @param string $userid The Joomla ID of the user
  646.  
  647. * @return object database Returns the userinfo as a Joomla database object
  648.  
  649. **/
  650.  
  651.  
  652.  
  653.     function lookupUser($jname, $userid)
  654.  
  655.     {
  656.  
  657.         $db =& JFactory::getDBO();
  658.  
  659.         $query = 'SELECT * FROM #__jfusion_users_plugin WHERE id =' . $userid . ' AND jname = ' . $db->quote($jname);
  660.  
  661.         $db->setQuery($query);
  662.  
  663.         $result = $db->loadObject();
  664.  
  665.         return $result;
  666.  
  667.     }
  668.  
  669.  
  670.  
  671.     /**
  672.  
  673. * Checks to see if a JFusion plugin is properly configured
  674.  
  675. * @param string $jname name of the JFusion plugin used
  676.  
  677. * @return bolean returns true if plugin is correctly configured
  678.  
  679. */
  680.  
  681.  
  682.  
  683.     function validPlugin($jname)
  684.  
  685.     {
  686.  
  687.         $db =& JFactory::getDBO();
  688.  
  689.         $query = 'SELECT status FROM #__jfusion WHERE name =' . $db->quote($jname);
  690.  
  691.         $db->setQuery($query);
  692.  
  693.         $result = $db->loadResult();
  694.  
  695.                 if ($result == '1') {
  696.  
  697.             $result = true;
  698.  
  699.             return $result;
  700.  
  701.                 } else {
  702.  
  703.             $result = false;
  704.  
  705.             return $result;
  706.  
  707.                 }
  708.  
  709.     }
  710.  
  711.  
  712.  
  713.     function removeUser($userinfo)
  714.  
  715.     {
  716.  
  717.         //Delete old user data in the lookup table
  718.  
  719.                 $db =& JFactory::getDBO();
  720.  
  721.         $query = 'DELETE FROM #__jfusion_users WHERE id =' . $userinfo->userid . ' OR username =' . $db->quote($userinfo->username);
  722.  
  723.         $db->setQuery($query);
  724.  
  725.                 if(!$db->query()) {
  726.  
  727.             JError::raiseWarning(0,$db->stderr());
  728.  
  729.         }
  730.  
  731.  
  732.  
  733.         $query = 'DELETE FROM #__jfusion_users_plugin WHERE id =' . $userinfo->userid ;
  734.  
  735.         $db->setQuery($query);
  736.  
  737.             if(!$db->query()) {
  738.  
  739.                 JError::raiseWarning(0,$db->stderr());
  740.  
  741.                 }
  742.  
  743.  
  744.  
  745.     }
  746.  
  747.  
  748.  
  749.     function addCookie($name, $value, $expires_time, $cookiepath, $cookiedomain, $httponly)
  750.  
  751.     {
  752.  
  753.         if($expires_time != 0) {
  754.  
  755.                         $expires = time() + intval($expires_time);
  756.  
  757.         } else {
  758.  
  759.                 $expires = 0;
  760.  
  761.         }
  762.  
  763.  
  764.  
  765.         // Versions of PHP prior to 5.2 do not support HttpOnly cookies and IE is buggy when specifying a blank domain so set the cookie manually
  766.  
  767.         $cookie = "Set-Cookie: {$name}=".urlencode($value);
  768.  
  769.         if ($expires > 0) {
  770.  
  771.             $cookie .= "; expires=".gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires);
  772.  
  773.         }
  774.  
  775.         if (!empty($cookiepath)) {
  776.  
  777.             $cookie .= "; path={$cookiepath}";
  778.  
  779.         }
  780.  
  781.         if (!empty($cookiedomain)) {
  782.  
  783.             $cookie .= "; domain={$cookiedomain}";
  784.  
  785.         }
  786.  
  787.         if ($httponly == true) {
  788.  
  789.             $cookie .= "; HttpOnly";
  790.  
  791.         }
  792.  
  793.  
  794.  
  795.                 header($cookie, false);
  796.  
  797.  
  798.  
  799.         //$document     = JFactory::getDocument();
  800.  
  801.             //$document->addCustomTag($cookie);
  802.  
  803.  
  804.  
  805.     }
  806.  
  807.  
  808.  
  809.     function raiseWarning($type, $warning, $jerror){
  810.  
  811.         if(is_array($warning)){
  812.  
  813.                         foreach ($warning as $warningtext){
  814.  
  815.                                 if ($jerror){
  816.  
  817.                                         JError::raiseWarning('500', $type . ': '. $warningtext);
  818.  
  819.                                 } else {
  820.  
  821.                                         echo $type . ': '. $warningtext . '<br/>';
  822.  
  823.                                 }
  824.  
  825.                         }
  826.  
  827.         } else {
  828.  
  829.                 if ($jerror) {
  830.  
  831.                                 JError::raiseWarning('500', $type .': '. $warning);
  832.  
  833.                 } else {
  834.  
  835.                                 echo $type . ': '. $warning . '<br/>';
  836.  
  837.                 }
  838.  
  839.         }
  840.  
  841.     }
  842.  
  843.  
  844.  
  845.         function phpinfo_array(){
  846.  
  847.                 //get the phpinfo and parse it into an array
  848.  
  849.                 ob_start();
  850.  
  851.                 phpinfo();
  852.  
  853.                 $phpinfo = array('phpinfo' => array());
  854.  
  855.                 if(preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER))
  856.  
  857.         foreach($matches as $match)
  858.  
  859.         if(strlen($match[1]))
  860.  
  861.         $phpinfo[$match[1]] = array();
  862.  
  863.         elseif(isset($match[3]))
  864.  
  865.         $phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
  866.  
  867.         else
  868.  
  869.         $phpinfo[end(array_keys($phpinfo))][] = $match[2];
  870.  
  871.  
  872.  
  873.         return $phpinfo;
  874.  
  875.         }
  876.  
  877.  
  878.  
  879.     function displayDonate(){
  880.  
  881.         ?>
  882.  
  883. <table class="adminform"><tr><td style="width:90%;"><font size="3"><b><?php echo JText::_('DONATION_MESSAGE'); ?></b></font></td><td style="width:10%; text-align:right;">
  884.  
  885. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  886.  
  887. <input type="hidden" name="cmd" value="_donations"/>
  888.  
  889. <input type="hidden" name="business" value="webmaster@jfusion.org"/>
  890.  
  891. <input type="hidden" name="item_name" value="jfusion.org"/>
  892.  
  893. <input type="hidden" name="no_shipping" value="0"/>
  894.  
  895. <input type="hidden" name="no_note" value="1"/>
  896.  
  897. <input type="hidden" name="currency_code" value="AUD"/>
  898.  
  899. <input type="hidden" name="tax" value="0"/>
  900.  
  901. <input type="hidden" name="lc" value="AU"/>
  902.  
  903. <input type="hidden" name="bn" value="PP-DonationsBF"/>
  904.  
  905. <input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal donation button."/>
  906.  
  907. <img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1"/>
  908.  
  909. </form></td></tr></table>
  910.  
  911.  
  912.  
  913.         <?php
  914.  
  915.  
  916.  
  917.     }
  918.  
  919.  
  920.  
  921.     function updateForumLookup($contentid, $threadid, $postid, $jname)
  922.  
  923.     {
  924.  
  925.         $db =& JFactory::getDBO();
  926.  
  927.                 $modified = time();
  928.  
  929.  
  930.  
  931.                 //check to see if content item has already been created in forum software
  932.  
  933.         $query = 'SELECT COUNT(*) FROM #__jfusion_forum_plugin WHERE contentid = ' . $contentid . ' AND jname = ' . $db->Quote($jname);
  934.  
  935.         $db->setQuery($query);
  936.  
  937.             if($db->loadResult() == 0)
  938.  
  939.             {
  940.  
  941.                 //content item has not been created
  942.  
  943.                 //prepare the variables
  944.  
  945.                 $lookup = new stdClass;
  946.  
  947.                 $lookup->contentid = $contentid;
  948.  
  949.                 $lookup->threadid = $threadid;
  950.  
  951.                 $lookup->postid = $postid;
  952.  
  953.                 $lookup->modified = $modified;
  954.  
  955.                 $lookup->jname = $jname;
  956.  
  957.  
  958.  
  959.                 //insert the entry into the lookup table
  960.  
  961.                 $db->insertObject('#__jfusion_forum_plugin', $lookup);
  962.  
  963.             }
  964.  
  965.             else
  966.  
  967.             {
  968.  
  969.                 //content itmem has been created so updated variables to prevent duplicate threads
  970.  
  971.                 $query = "UPDATE #__jfusion_forum_plugin SET threadid = {$threadid}, postid = {$postid}, modified = {$modified} WHERE contentid = {$contentid} AND jname = {$db->Quote($jname)}";
  972.  
  973.                 $db->setQuery($query);
  974.  
  975.                 $db->query();
  976.  
  977.             }
  978.  
  979.     }
  980.  
  981.  
  982.  
  983.     function createJoomlaArticleURL($contentid,$text)
  984.  
  985.     {
  986.  
  987.                 $link = JRoute::_('index.php?option=com_content&view=article&id=' . $contentid);
  988.  
  989.                 $link = "<a href='$link'>$text</a>";
  990.  
  991.                 return $link;
  992.  
  993.     }
  994.  
  995. }