· 8 years ago · Jun 17, 2018, 04:02 PM
1<?php
2
3
4
5////////////// common.php //////////////
6
7+function prepare_search_tables($search_params, $db)
8+{
9+
10+ if (is_null($db) || !is_object($db) || (get_class($db) != 'DatingDB'))
11+ {
12+ trigger_error("Incorrect database object", E_USER_ERROR);
13+ return;
14+ }
15+
16+ if ($search_params['incoming_winks'])
17+ {
18+ $db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS incoming_winks_search (from_id INT NOT NULL)");
19+ $db->Execute("TRUNCATE incoming_winks_search");
20+ $db->Execute("INSERT incoming_winks_search SELECT from_id FROM winks WHERE to_id=:i:to_id:", array('to_id' => current_user_id()));
21+ $db->Execute("ALTER TABLE incoming_winks_search ENGINE MEMORY");
22+ }
23+
24+ if ($search_params['outgoing_winks'])
25+ {
26+ $db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS outgoing_winks_search (to_id INT NOT NULL)");
27+ $db->Execute("TRUNCATE outgoing_winks_search");
28+ $db->Execute("INSERT outgoing_winks_search SELECT to_id FROM winks WHERE from_id=:i:from_id:", array('from_id' => current_user_id()));
29+ $db->Execute("ALTER TABLE outgoing_winks_search ENGINE MEMORY");
30+ }
31+
32+ if ($search_params['who_viewed'])
33+ {
34+ $sub_sql = "CREATE TEMPORARY TABLE IF NOT EXISTS `profiles_activities_search`
35+ (
36+ `id` int NOT NULL,
37+ `tdate` int(11) NOT NULL default '0',
38+ PRIMARY KEY (`id`)
39+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
40+
41+ if($db->execute($sub_sql))
42+ {
43+ $db->execute("TRUNCATE TABLE `profiles_activities_search`");
44+
45+ $sub_sql = "INSERT IGNORE INTO profiles_activities_search (id, tdate)
46+
47+ (SELECT pa.from_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.to_id= " . intval($_SESSION['MEMBER']['id']) . "
48+ AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and sentbrowse = 1)
49+
50+ UNION
51+
52+ (SELECT pa.to_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.from_id= " . intval($_SESSION['MEMBER']['id']) . "
53+ AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and gotbrowse = 1)";
54+
55+ $db->execute($sub_sql);
56+
57+ $db->execute("ALTER TABLE profiles_activities_search ENGINE MEMORY");
58+ }
59+ else
60+ {
61+ $result['profiles_activities_search'] = false;
62+
63+ }
64+
65+ unset($_SESSION['SESSION']['LAST_FSEARCH_SQL']);
66+ }
67+
68+ return $result;
69+}
70+
71
72
73
74
75
76////////////// flirtcast.php //////////////
77
78@@ -207,6 +207,7 @@
79
80 $SQL->create($sqls[0]);
81
82+ prepare_search_tables($_SESSION['SEARCH']['ProfilesSettings'], $DB);
83 $flirtcast_recipients = $DB->GetCol($SQL);
84
85 $DB->balancing_on();
86@@ -287,6 +288,7 @@
87
88 $SQL->create($sqls[0]);
89
90+ prepare_search_tables($_SESSION['SEARCH']['ProfilesSettings'], $DB);
91 $flirtcast_recipients = $DB->GetCol($SQL);
92
93 $DB->balancing_on();
94@@ -373,6 +375,7 @@
95
96 $SQL->create($sqls[0]);
97
98+ prepare_search_tables($_SESSION['SEARCH']['ProfilesSettings'], $DB);
99 $flirtcast_recipients = $DB->GetCol($SQL);
100
101
102
103
104
105////////////// profile.get.php //////////////
106
107 unset($_DATA['siteid']);
108 $_DATA['siteid'] = get_group_sites_id(getSiteID());
109-
110- if(!empty($_DATA['who_viewed']))
111- {
112- $sub_sql = "CREATE TEMPORARY TABLE IF NOT EXISTS `profiles_activities_search`
113- (
114- `id` int NOT NULL,
115- `tdate` int(11) NOT NULL default '0',
116- PRIMARY KEY (`id`)
117- ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
118
119- if($db->execute($sub_sql))
120- {
121- $db->execute("TRUNCATE TABLE `profiles_activities_search`");
122-
123- $sub_sql = "INSERT IGNORE INTO profiles_activities_search (id, tdate)
124-
125- (SELECT pa.from_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.to_id= " . intval($_SESSION['MEMBER']['id']) . "
126- AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and sentbrowse = 1)
127
128- UNION
129-
130- (SELECT pa.to_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.from_id= " . intval($_SESSION['MEMBER']['id']) . "
131- AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and gotbrowse = 1)";
132-
133- $db->execute($sub_sql);
134-
135- $db->execute("ALTER TABLE profiles_activities_search ENGINE MEMORY");
136- }
137- else
138- {
139- return;
140- }
141-
142- unset($_SESSION['SESSION']['LAST_FSEARCH_SQL']);
143+ $search_tables = prepare_search_tables($_DATA,db());
144+
145+ if(!empty($_DATA['who_viewed']))
146+ {
147+ if(isset($search_tables['profiles_activities_search'])
148+ && $search_tables['profiles_activities_search']===false)
149+ {
150+ return;
151+ }
152 }
153 elseif(!empty($_DATA['st']) && $_DATA['st'] == 'B')
154 {
155@@ -690,11 +669,6 @@
156 if(is_array($flircast_enabled) and in_array('incoming_winks',$flircast_enabled)) {
157 $_SESSION['SEARCH']['ProfilesSettings']['enable_flirtcast_in_search'] = true;
158 }
159-
160- db()->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS incoming_winks_search (from_id INT NOT NULL)");
161- db()->Execute("TRUNCATE incoming_winks_search");
162- db()->Execute("INSERT incoming_winks_search SELECT from_id FROM winks WHERE to_id=:i:to_id:", array('to_id' => current_user_id()));
163- db()->Execute("ALTER TABLE incoming_winks_search ENGINE MEMORY");
164 }
165
166 if (!empty($_DATA['outgoing_winks'])) {
167@@ -702,11 +676,6 @@
168 if(is_array($flircast_enabled) and in_array('outgoing_winks',$flircast_enabled)) {
169 $_SESSION['SEARCH']['ProfilesSettings']['enable_flirtcast_in_search'] = true;
170 }
171-
172- db()->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS outgoing_winks_search (to_id INT NOT NULL)");
173- db()->Execute("TRUNCATE outgoing_winks_search");
174- db()->Execute("INSERT outgoing_winks_search SELECT to_id FROM winks WHERE from_id=:i:from_id:", array('from_id' => current_user_id()));
175- db()->Execute("ALTER TABLE outgoing_winks_search ENGINE MEMORY");
176 }
177
178 $order_by = isset($_DATA['st']) ? $_DATA['st'] : '';
179
180
181
182 ?>