3 require_once("boot.php");
9 @include(".htconfig.php");
10 require_once("dba.php");
11 $db = new dba($db_host, $db_user, $db_pass, $db_data);
12 unset($db_host, $db_user, $db_pass, $db_data);
15 $a->set_baseurl("https://pirati.ca");
18 function create_tags_from_item($itemid) {
21 $profile_base = $a->get_baseurl();
22 $profile_data = parse_url($profile_base);
23 $profile_base_friendica = $profile_data['host'].$profile_data['path']."/profile/";
24 $profile_base_diaspora = $profile_data['host'].$profile_data['path']."/u/";
26 $searchpath = $a->get_baseurl()."/search?tag=";
28 $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
33 $message = $messages[0];
36 q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
37 intval(TERM_OBJ_POST),
40 intval(TERM_MENTION));
42 if ($message["deleted"])
45 $taglist = explode(",", $message["tag"]);
48 foreach ($taglist as $tag)
49 if ((substr(trim($tag), 0, 1) == "#") OR (substr(trim($tag), 0, 1) == "@"))
50 $tags .= " ".trim($tag);
52 $tags .= " #".trim($tag);
54 $data = " ".$message["title"]." ".$message["body"]." ".$tags." ";
58 $pattern = "/\W\#([^\[].*?)[\s'\".,:;\?!\[\]\/]/ism";
59 if (preg_match_all($pattern, $data, $matches))
60 foreach ($matches[1] as $match)
61 $tags["#".strtolower($match)] = ""; // $searchpath.strtolower($match);
63 $pattern = "/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism";
64 if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
65 foreach ($matches as $match)
66 $tags[$match[1].strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2];
69 foreach ($tags as $tag=>$link) {
71 if (substr(trim($tag), 0, 1) == "#") {
73 $term = substr($tag, 1);
74 } elseif (substr(trim($tag), 0, 1) == "@") {
76 $term = substr($tag, 1);
77 } else { // This shouldn't happen
82 $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')",
83 intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term), dbesc($link));
85 // Search for mentions
86 if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
87 $users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link);
88 foreach ($users AS $user) {
89 if ($user["uid"] == $message["uid"])
90 q("UPDATE `item` SET `mention` = 1 WHERE `id` = %d", intval($itemid));
96 function create_tags_from_itemuri($itemuri, $uid) {
97 $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
99 foreach ($messages as $message)
100 create_tags_from_item($message["id"]);
103 function update_items() {
104 //$messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC limit 10");
105 $messages = q("SELECT `id` FROM `item` where tag !=''");
107 foreach ($messages as $message)
108 create_tags_from_item($message["id"]);
112 //print_r($hashtags);
113 //print_r($mentions);
115 //create_tags_from_item(265194);
116 //create_tags_from_itemuri("infoagent@diasp.org:cce94abd104c06e8", 2);