function loadLink( $link_id, &$savantConf, &$fields, &$params ) { global $_MAMBOTS, $mtconf; $database =& JFactory::getDBO(); $jdate = JFactory::getDate(); $now = $jdate->toMySQL(); $nullDate = $database->getNullDate(); # Get all link data $database->setQuery( "SELECT l.*, u.username AS username, u.name AS owner, u.email AS owner_email, cl.cat_id AS cat_id, c.cat_name AS cat_name, img.filename AS link_image, img.img_id FROM (#__mt_links AS l, #__mt_cl AS cl)" . "\n LEFT JOIN #__users AS u ON u.id = l.user_id" . "\n LEFT JOIN #__mt_cats AS c ON c.cat_id = cl.cat_id" . "\n LEFT JOIN #__mt_images AS img ON img.link_id = l.link_id AND img.ordering = 1" . "\n WHERE link_published='1' AND link_approved > 0 AND l.link_id='".$link_id."' " . "\n AND ( publish_up = ".$database->Quote($nullDate)." OR publish_up <= '$now' ) " . "\n AND ( publish_down = ".$database->Quote($nullDate)." OR publish_down >= '$now' ) " . "\n AND l.link_id = cl.link_id" . "\n LIMIT 1" ); $link = $database->loadObject(); if(count($link)==0) return false; # Use owner's email address is listing e-mail is not available if ( $mtconf->get('use_owner_email') && empty($link->email) && $link->user_id > 0 ) { $link->email = $link->owner_email; } # Load link's template if ( empty($link->link_template) ) { // Get link's template $database->setQuery( "SELECT cat_template FROM #__mt_cats WHERE cat_id='".$link->cat_id."' LIMIT 1" ); $cat_template = $database->loadResult(); if ( !empty($cat_template) ) { loadCustomTemplate(null,$savantConf,$cat_template); } } else { loadCustomTemplate(null,$savantConf,$link->link_template); } # Load fields $fields = loadFields( $link ); # Load custom fields' value from #__mt_cfvalues to $link $database->setQuery( "SELECT CONCAT('cust_',cf_id) as varname, value FROM #__mt_cfvalues WHERE link_id = '".$link_id."'" ); $cfvalues = $database->loadObjectList('varname'); foreach( $cfvalues as $cfkey => $cfvalue ) { $link->$cfkey = $cfvalue->value; } # Parameters $params = new JRegistry( $link->attribs ); $params->def( 'show_review', $mtconf->get('show_review')); $params->def( 'show_rating', $mtconf->get('show_rating' )); return $link; }
/** * This function can be called from LO insert/edit operation * to set position in homerepo and other metadata. * @param $lo instance of the learning object to edit * @param $withForm print form tag * @param $withContents display the Items in folders * @param $idLO id of learning object to change. If this parameter is not NULL * $lo is ignored **/ function manHomeRepoSave(&$lo, $withForm = FALSE, $withContents = TRUE, $treeView = NULL, $idLO = NULL) { if ($treeView === NULL) { $treeView = manHomerepo_CreateTreeView($withContents, FALSE); } // print a form that submit to the same url if ($withForm) { echo '<form name="manHomerepo" method="post"' . ' action="index.php?' . $_SERVER['QUERY_STRING'] . '"' . ' >' . "\n" . '<input type="hidden" id="authentic_request_hr" name="authentic_request" value="' . Util::getSignature() . '" />'; } if ($treeView->cancel) { if (isset($_POST['idLO'])) { Util::jump_to('index.php?modname=homerepo&op=homerepo'); } else { Util::jump_to('' . $lo->getBackUrl()); } } // handle operations switch ($treeView->op) { case 'newfolder': manHomerepo_addfolder($treeView); break; case 'save': if (isset($_POST['idLO'])) { manHomerepo_update($treeView->getSelectedFolderId(), $_POST['idLO'], $_POST); Util::jump_to('index.php?modname=homerepo&op=homerepo'); } else { manHomerepo_save($treeView->getSelectedFolderId(), $lo, $_POST); Util::jump_to('' . $lo->getBackUrl()); } break; case 'display': default: echo '<div class="std_block">'; manHomerepo_display($treeView, $withContents); loadFields($_POST, $lo, $idLO); // add save button echo '<img src="' . $treeView->_getSaveImage() . '" alt="' . _SAVE . '" /> ' . '<input type="submit" value="' . _SAVE . '" class="LVAction"' . ' name="' . $treeView->_getOpSaveFile() . '" />'; echo ' <img src="' . $treeView->_getCancelImage() . '" alt="' . $treeView->_getCancelAlt() . '" />' . '<input type="submit" class="LVAction" value="' . $treeView->_getCancelLabel() . '"' . ' name="' . $treeView->_getCancelId() . '" id="' . $treeView->_getCancelId() . '" />'; echo '</div>'; break; } if ($withForm) { echo '</form>' . "\n"; } }
/** * This function can be called from LO insert/edit operation * to set position in pubrepo and other metadata. * @param $lo instance of the learning object to edit * @param $withForm print form tag * @param $withContents display the Items in folders **/ function manPubRepoSave(&$lo, $withForm = FALSE, $withContents = TRUE) { $treeView = manPubrepo_CreateTreeView($withContents, FALSE); // print a form that submit to the same url if ($withForm) { echo '<form name="manPubrepo" method="post"' . ' action="index.php?' . $_SERVER['QUERY_STRING'] . '"' . ' >' . "\n" . '<input type="hidden" id="authentic_request_pr" name="authentic_request" value="' . Util::getSignature() . '" />'; } // handle operations switch ($treeView->op) { case 'newfolder': manPubrepo_addfolder($treeView); break; case 'save': manPurepo_save($treeView->getSelectedFolderId(), $lo, $_POST); Util::jump_to('' . $lo->getBackUrl()); case 'display': default: manPubrepo_display($treeView, $withContents); loadFields($_POST, $lo); break; } // add save button echo '<img src="' . getPathImage() . 'standard/save.gif" alt="' . _SAVE . '" /> ' . '<input type="submit" value="' . _SAVE . '"' . ' name="' . $treeView->_getOpSaveFile() . '" />'; if ($withForm) { echo '</form>' . "\n"; } }
function viewlink($link_id, $my, $limitstart, $option) { global $savantConf, $mtconf; $link = loadLink($link_id, $savantConf, $fields, $params); $document =& JFactory::getDocument(); if ($link === false) { if ($mtconf->get('unpublished_message_cfid') > 0) { $database =& JFactory::getDBO(); $database->setQuery('SELECT l.*, u.username AS username FROM #__mt_links AS l ' . 'LEFT JOIN #__users AS u ON u.id = l.user_id ' . 'WHERE link_id = ' . $database->quote($link_id) . ' LIMIT 1'); $link = $database->loadObject(); if ($link->link_published == 0) { $database->setQuery('SELECT value FROM #__mt_cfvalues WHERE link_id = ' . $database->quote($link_id) . ' AND cf_id = ' . $database->quote($mtconf->get('unpublished_message_cfid')) . ' LIMIT 1'); $unpublished_message = $database->loadResult(); if (!empty($unpublished_message)) { $params =& new JParameter($link->attribs); $savant = new Savant2($savantConf); $fields = loadFields($link); assignCommonViewlinkVar($savant, $link, $fields, $pathWay, $params); $unpublished_message_cf = $fields->getFieldById($mtconf->get('unpublished_message_cfid')); $unpublished_message = $unpublished_message_cf->getOutput(); $savant->assign('error_msg', JText::sprintf('This listing has been unpublished for the following reason:', $unpublished_message)); $savant->assign('my', $my); $savant->display('page_errorListing.tpl.php'); } else { JError::raiseError(404, JText::_('Resource Not Found')); } } else { JError::raiseError(404, JText::_('Resource Not Found')); } } else { JError::raiseError(404, JText::_('Resource Not Found')); } } else { # Set Page Title $document->setTitle($link->link_name); # Add META tags if ($mtconf->getjconf('MetaTitle') == '1') { $document->setMetadata('title', htmlspecialchars($link->link_name)); } if ($mtconf->getjconf('MetaAuthor') == '1') { $document->setMetadata('author', htmlspecialchars($link->owner)); } if (!empty($link->metadesc)) { $document->setDescription(htmlspecialchars($link->metadesc)); } elseif (!empty($link->link_desc)) { $metadesc_maxlength = 300; // Get the first 300 characters $metadesc = JString::trim(strip_tags($link->link_desc)); $metadesc = JString::str_ireplace("\r\n", "", $metadesc); $metadesc = JString::substr($metadesc, 0, $metadesc_maxlength); // Make sure the meta description is complete and is not truncated in the middle of a sentence. if (JString::strlen($link->link_desc) > $metadesc_maxlength && substr($metadesc, -1, 1) != '.') { if (strrpos($metadesc, '.') !== false) { $metadesc = JString::substr($metadesc, 0, JString::strrpos($metadesc, '.') + 1); } } $document->setDescription(htmlspecialchars($metadesc)); } if ($link->metakey != '') { $document->setMetaData('keywords', $link->metakey); } $document->addCustomTag(' <script src="' . $mtconf->getjconf('live_site') . $mtconf->get('relative_path_to_js_library') . '" type="text/javascript"></script>'); $document->addCustomTag(' <script src="' . $mtconf->getjconf('live_site') . '/components/com_mtree/js/vote.js" type="text/javascript"></script>'); # Predefine variables: $prevar = " <script type=\"text/javascript\"><!-- \n"; $prevar .= "jQuery.noConflict();\n"; $prevar .= "var mtoken=\"" . JUtility::getToken() . "\";\n"; $prevar .= "var mosConfig_live_site=\"" . $mtconf->getjconf('live_site') . "\";\n"; $prevar .= "var langRateThisListing=\"" . JText::_('Rate this listing', true) . "\";\n"; $prevar .= "var ratingText=new Array();\n"; $prevar .= "ratingText[5]=\"" . JText::_('Rating 5', true) . "\";\n"; $prevar .= "ratingText[4]=\"" . JText::_('Rating 4', true) . "\";\n"; $prevar .= "ratingText[3]=\"" . JText::_('Rating 3', true) . "\";\n"; $prevar .= "ratingText[2]=\"" . JText::_('Rating 2', true) . "\";\n"; $prevar .= "ratingText[1]=\"" . JText::_('Rating 1', true) . "\";\n"; $prevar .= "//--></script>"; $document->addCustomTag($prevar); if (!empty($my->id) && !$mtconf->get('cache_registered_viewlink')) { viewlink_cache($link, $limitstart, $fields, $params, $my, $option); } else { $cache =& JFactory::getCache('com_mtree'); $cache->call('viewlink_cache', $link, $limitstart, $fields, $params, $my, $option); } } }