/** * Accepts html in which every hyper links needs to be replaced by tracker links * @param $html contains Plain HTML * @return returns array that consist converted html and row ids of links has been inserted. */ static function getHtmlWithTrackerLinks($html) { global $logger; $link_ids = array(); $pattern = '/href=\\"([^\\"]*)\\"/'; $links = array(); $db = new Dbase("msging"); $num_links = preg_match_all($pattern, $html, $links, PREG_PATTERN_ORDER) . "\n"; $links = $links[1]; $links = array_unique($links); $num_links = count($links); $new_html = $html; $values = array(); foreach ($links as $link) { if ($link != '' || $link != '#') { $value = " ( -1 , '" . $link . "' , 0 )"; array_push($values, $value); } } $values = implode(',', $values); $sql = "INSERT INTO `email_links_redirection`( `message_id` , `url` ,`clicks` ) VALUES {$values}"; $first_value = $db->insert($sql); if ($first_value) { $logger->info("Success: {$sql}"); $cnt = 0; foreach ($links as $link) { if ($link != '' || $link != '#') { $link_ids[$cnt++] = $first_value; $str = base64_encode($first_value); $url = "http://intouch.capillary.co.in/linktracker.php?link_id=" . urlencode($str); $logger->info("set tracker Link: {$url}"); $count = 1; $new_html = str_replace($link, $url, $new_html, $count); $first_value++; } } } return array($new_html, $link_ids); }