| 76 | | /** Get the clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ |
| 77 | | public static function getClickThroughLink($hyperlink, Content &$content, $node, $user) { |
| 78 | | $node?$node_id=urlencode($node->getId()):$node_id=null; |
| 79 | | $user?$user_id=urlencode($user->getId()):$user_id=null; |
| 80 | | return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=".urlencode($content->getId())."&node_id={$node_id}&user_id={$user_id}"; |
| | 77 | /** Get the clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ |
| | 78 | private static function getClickThroughLink($hyperlink, Content & $content, $node, $user) { |
| | 79 | $node ? $node_id = urlencode($node->getId()) : $node_id = null; |
| | 80 | $user ? $user_id = urlencode($user->getId()) : $user_id = null; |
| | 81 | return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=" . urlencode($content->getId()) . "&node_id={$node_id}&user_id={$user_id}"; |
| 83 | | /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ |
| 84 | | public static function replaceHyperLinks(&$string, Content &$content) { |
| 85 | | $links = self :: findHyperLinks($string); |
| 86 | | if(!empty($links)) |
| 87 | | { |
| 88 | | $node = Node::getCurrentNode(); |
| 89 | | $user = User::getCurrentUser(); |
| 90 | | foreach ($links as $link) { |
| 91 | | $replacements[] = self :: getClickThroughLink($link, $content, $node, $user); |
| 92 | | } |
| 93 | | //pretty_print_r($replacements); |
| 94 | | return str_replace($links, $replacements, $string); |
| 95 | | } |
| 96 | | else |
| 97 | | { |
| | 84 | /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ |
| | 85 | public static function replaceHyperLinks(& $string, Content & $content) { |
| | 86 | $matches = self :: findHyperLinks($string); |
| | 87 | //pretty_print_r($matches); |
| | 88 | if (!empty ($matches[2])) { |
| | 89 | $node = Node :: getCurrentNode(); |
| | 90 | $user = User :: getCurrentUser(); |
| | 91 | $i = 0; |
| | 92 | foreach ($matches[2] as $link) { |
| | 93 | $new_link = self :: getClickThroughLink($link, $content, $node, $user); |
| | 94 | $replacements[] = $matches[1][$i] . $new_link . $matches[3][$i]; |
| | 95 | $i++; |
| | 96 | } |
| | 97 | //pretty_print_r($replacements); |
| | 98 | return str_replace($matches[0], $replacements, $string); |
| | 99 | } else { |