· 5 years ago · Nov 08, 2020, 06:54 PM
1<?php
2
3error_reporting(30719 & ~8);
4require "../includes/prepare.php";
5require "../includes/libs/cache.php";
6require "../includes/libs/img_functions.php";
7require "../includes/libs/http_functions.php";
8require "../includes/libs/Log.class.php";
9if (!defined("BASE_DIR")) {
10 define("BASE_DIR", "../");
11}
12$config["db_log_errors"] = true;
13set_time_limit(3600);
14ini_set("display_errors", true);
15if (!$rot_settings["works"]) {
16 exit;
17}
18parse_command_line();
19if (isset($_REQUEST["verbose"]) && $_REQUEST["verbose"] == 3) {
20 $GLOBALS["config"]["debug"] = true;
21}
22if (!$_SERVER["HTTP_HOST"] || trim($_SERVER["HTTP_HOST"]) == "") {
23 write_script_warning("Rotation warning: you run rotation.php without the HTTP_HOST variable. This can affect traffic counting, please fix crontab job.", "core_errors");
24}
25if (!$config["cache_prefix"]) {
26 $config["cache_prefix"] = str_replace("www.", "", $_SERVER["HTTP_HOST"]);
27}
28Log::SetLogFile("rotation.log");
29Log::SetVerboseLevel($config["verbose"]);
30check_ext_rotation();
31process_extra_functions();
32if ($config["verbose"] == 3 && $_REQUEST["debug"]) {
33 $config["debug"] = true;
34}
35writelog("Rotation Started");
36register_shutdown_function("local_shudown");
37if ($_GET["action"] != "preview" && !$_REQUEST["prepare_tube_vars"] && !$_REQUEST["process_deleted"]) {
38 check_double_run();
39}
40$r = db_query("select * from rot_groups as g left join rot_groups_data as gd on g.id = gd.group_id where site_id = '" . (int) $rot_settings["linked_db_id"] . "' ", $rot_settings["db_link"]);
41while ($d = db_fetch_assoc($r)) {
42 $rot_groups[$d["id"]] = $d["name"];
43 $group2id[$d["name"]] = $d["id"];
44 $groups[$d["id"]] = $d;
45}
46$sponsors = rot_get_sponsors();
47if ($_GET["action"] == "preview") {
48 $verbose = 0;
49 rotate_thumbs();
50 include "../includes/end.php";
51 exit;
52}
53if (!$config["process_clicks_interval"] || date("i") % $config["process_clicks_interval"] == 0) {
54 writelog("Process clicks");
55 process_clicks();
56}
57if ($rot_settings["force_rotation"] == "create_cat0") {
58 writelog("Forcing cat0 from admin ");
59 $_REQUEST["create_tube_category_thumb"] = true;
60 $_REQUEST["create_tube_category_thumb2"] = true;
61 $rot_settings["force_rotation"] = "";
62 db_query("UPDATE rot_settings SET value = '' WHERE name = 'force_rotation' ");
63} else {
64 if ($rot_settings["force_rotation"] == "reset_models") {
65 $rot_settings["force_rotation"] = "";
66 db_query("UPDATE rot_settings SET value = '' WHERE name = 'force_rotation' ");
67 reset_models();
68 } else {
69 if ($rot_settings["force_rotation"] == "clear_cache") {
70 $rot_settings["force_rotation"] = "";
71 db_query("UPDATE rot_settings SET value = '' WHERE name = 'force_rotation' ");
72 Cache::flush();
73 writelog("Clear Cache (scheduled) : done");
74 } else {
75 if ($rot_settings["force_rotation"] == "reset_thumb_cats") {
76 $rot_settings["force_rotation"] = "";
77 db_query("UPDATE rot_settings SET value = '' WHERE name = 'force_rotation' ");
78 reset_thumb_cats();
79 } else {
80 if (15 < strlen($rot_settings["force_rotation"])) {
81 $rot_settings["force_rotation"] = unserialize($rot_settings["force_rotation"]);
82 db_query("UPDATE rot_settings SET value = '' WHERE name = 'force_rotation' ");
83 if ($rot_settings["force_rotation"]["action"] == "reassign_tags") {
84 reassign_tags($rot_settings["force_rotation"]);
85 } else {
86 if ($rot_settings["force_rotation"]["action"] == "delete_tested_thumbs") {
87 delete_tested_thumbs($rot_settings["force_rotation"]["delete_tested_limit"]);
88 } else {
89 if ($rot_settings["force_rotation"]["action"] == "synomize_all_description") {
90 synomize_all_descriptions();
91 } else {
92 if ($rot_settings["force_rotation"]["action"] == "tube_init_thumbs") {
93 tube_init_thumbs();
94 } else {
95 if ($rot_settings["force_rotation"]["action"] == "assign_groups_by_tags") {
96 assign_groups_by_tags();
97 }
98 }
99 }
100 }
101 }
102 $rot_settings["force_rotation"] = "";
103 }
104 }
105 }
106 }
107}
108if ($rot_settings["linked_db_id"] == 1) {
109 process_shift();
110}
111rotate_thumbs();
112if ($_REQUEST["clean_rot_page_items"] || run_periodical_function("clean_rot_page_items", 86400, 3500, "tomorrow 23:00")) {
113 writelog("Clean rot_page_items");
114 db_query("DELETE FROM rot_page_items WHERE date < '" . date("Y-m-d", time() - 86400) . "' ");
115 $tables = $check_tables = array();
116 $q = db_query("SHOW TABLE STATUS ");
117 while ($d = db_fetch_assoc($q)) {
118 $tables[$d["Name"]] = $d;
119 }
120 if ($tables["rot_page_items"]["Engine"] != "InnoDB") {
121 db_query("OPTIMIZE TABLE rot_page_items");
122 }
123}
124if ($_REQUEST["clean_rot_search_queries"] || run_periodical_function("clean_rot_search_queries", 86400, 3500)) {
125 writelog("Deleting rot_search_log older than " . $settings["history_length"] . " days");
126 db_query("DELETE FROM rot_search_queries WHERE date < '" . date("Y-m-d", time() - $settings["history_length"] * 86400) . "' ");
127}
128if ($_REQUEST["prepare_tube_vars"] || $rot_settings["prepare_tube_vars"]) {
129 db_query("UPDATE rot_settings SET value = '' WHERE name = 'prepare_tube_vars' ");
130 $_REQUEST["recreate_cache_password_timeout"] = true;
131 $_REQUEST["create_tube_category_thumb"] = true;
132 $_REQUEST["calculate_sponsor_galleries"] = true;
133 $_REQUEST["set_sponsor_cache"] = true;
134 $_REQUEST["calculate_model_galleries"] = true;
135 $_REQUEST["set_model_cache"] = true;
136 $_REQUEST["create_tag_cloud"] = true;
137 $_REQUEST["create_tag_thumbs"] = true;
138 $_REQUEST["create_model_thumbs"] = true;
139}
140if ($_REQUEST["recreate_cache_password_timeout"] || run_periodical_function("recreate_cache_password_timeout", 1800, 1800)) {
141 db_query("UPDATE rot_settings SET value = '' WHERE name = 'recreate_cache_password' ");
142}
143foreach (array("", 2, 3) as $z => $set_id) {
144 if (($_REQUEST["create_tube_category_thumb"] || run_periodical_function("create_tube_category_thumb" . $set_id, $rot_settings["tube_category_thumb_interval"] * 60, rand(800, 1000))) && $rot_settings["tube_category_thumb" . $set_id] && $rot_settings["tube_category_thumb_interval"]) {
145 writelog("Create Category thumbs (set " . $set_id . ")");
146 $sites = array(array("rot_linked_id" => (int) $rot_settings["linked_db_id"], "separate_thumb_stats" => 1, "separate_category_stats" => 1));
147 $q = "SELECT * FROM rot_linked_db WHERE translation_source = '" . (int) $rot_settings["linked_db_id"] . "' ";
148 if (!$rot_settings["slave_unique_cat_thumbs"]) {
149 $q .= " and (separate_category_stats = 1 or separate_thumb_stats = 1) ";
150 }
151 $q = db_query($q, $rot_settings["db_link"]);
152 while ($d = db_fetch_assoc($q)) {
153 $sites[] = $d;
154 }
155 foreach ($sites as $z => $site_d) {
156 if (!$site_d["separate_category_stats"]) {
157 continue;
158 }
159 if (!$site_d["separate_thumb_stats"]) {
160 writelog("Category thumbs " . $site_d["linked_db_name "] . " :: no separate thumb stats = copy cat thumbs");
161 writelog("No separate stats for " . $site_d["linked_db_name"] . ", coping stats .. ");
162 $q = db_query("SELECT gi.*, rt.thumb_url FROM rot_gallery_info as gi \r\n\t\t\t\t\tLEFT JOIN rot_thumbs as rt on rt.gallery_id = gi.gallery_id\r\n\t\t\t\t\tWHERE gi.gallery_type = 1 and gi.source_url = '1' \r\n\t\t\t\t\tand content_type = '" . (int) $set_id . "' \r\n\t\t\t\t\t", $rot_settings["db_link"]);
163 while ($d = db_fetch_assoc($q)) {
164 $stats = db_get_row("SELECT * FROM rot_gallery_stats1 WHERE gallery_id = '" . $d["gallery_id"] . "' ", $rot_settings["db_link"]);
165 $data = db_get_row("SELECT * FROM rot_gallery_data1 WHERE gallery_id = '" . $d["gallery_id"] . "' ", $rot_settings["db_link"]);
166 unset($d["gallery_id"]);
167 $d["source_url"] = $site_d["rot_linked_id"];
168 $d1 = db_get_row("SELECT gi.*, rt.thumb_url FROM rot_gallery_info as gi \r\n\t\t\t\t\t\tLEFT JOIN rot_thumbs as rt on rt.gallery_id = gi.gallery_id\r\n\t\t\t\t\t\tWHERE gi.gallery_type = 1 and gi.source_url = '" . (int) $site_d["rot_linked_id"] . "' \r\n\t\t\t\t\t\tand gi.url = '" . (int) $d["url"] . "'\r\n\t\t\t\t\t\tand content_type = '" . (int) $set_id . "'", $rot_settings["db_link"]);
169 if ($d1) {
170 if ($d["thumb_url"] != $d1["thumb_url"]) {
171 db_query("UPDATE rot_thumbs SET thumb_url = '" . addslashes($d["thumb_url"]) . "' WHERE gallery_id = '" . (int) $d1["gallery_id"] . "' ", $rot_settings["db_link"]);
172 writelog("Category " . $d["url"] . ", updating thumb_url ");
173 }
174 db_query("UPDATE rot_gallery_info as gi \r\n\t\t\t\t\t\t\tSET content_count = '" . (int) $d["content_count"] . "' \r\n\t\t\t\t\t\t\tWHERE gi.gallery_type = 1 and gi.source_url = '" . (int) $site_d["rot_linked_id"] . "' \r\n\t\t\t\t\t\t\tand gi.url = '" . (int) $d["url"] . "'\r\n\t\t\t\t\t\t\tand content_type = '" . (int) $set_id . "'");
175 writelog("Category " . $d["url"] . " exits ");
176 continue;
177 }
178 unset($d["thumb_url"]);
179 db_perform("rot_gallery_info", $d, "insert", "", $rot_settings["db_link"]);
180 $new_gallery_id = db_insert_id($rot_settings["db_link"]);
181 $stats["gallery_id"] = $new_gallery_id;
182 db_perform("rot_gallery_stats" . $site_d["rot_linked_id"], $stats, "insert", "", $rot_settings["db_link"]);
183 $data["gallery_id"] = $new_gallery_id;
184 db_perform("rot_gallery_data1", $data, "insert", "", $rot_settings["db_link"]);
185 }
186 continue;
187 }
188 $cat0_task = array("cat0_type" => "cat0", "set_id" => (int) $set_id, "thumb_shift" => $rot_settings["tube_category_thumb" . $set_id] != "date_last" ? cat0_thumb_shift($rot_settings["tube_category_thumb" . $set_id]) : "date_last", "content_type" => $rot_settings["tube_category_thumb_content_type" . $set_id], "site_id" => $site_d["rot_linked_id"], "site_stat_id" => $site_d["separate_thumb_stats"] ? $site_d["rot_linked_id"] : 1);
189 if (trim($rot_settings["tube_category_thumb_skip_group" . $set_id]) != "") {
190 $cat0_task["skip_group_ids"] = explode(",", trim($rot_settings["tube_category_thumb_skip_group" . $set_id]));
191 }
192 cat0_categories($cat0_task);
193 }
194 }
195}
196if (0 < $rot_settings["autodelete_thumbs_period"] && ($_REQUEST["autodelete_thumbs"] || run_periodical_function("autodelete_thumbs", (int) $rot_settings["autodelete_thumbs_period"] * 3600, 600))) {
197 writelog("AutoDelete thumbs: Delete min_shows " . $rot_settings["autodelete_thumbs_min_shows"] . ", CTR lower then " . $rot_settings["autodelete_thumbs_max_ctr"] . ", group list " . $rot_settings["autodelete_thumbs_group_ids"] . ", sponsor list " . $rot_settings["autodelete_thumbs_sponsor_ids"] . " ");
198 $sql = "UPDATE rot_thumbs SET thumb_status = 'to_delete' \r\n\t\t\tWHERE thumb_id IN (\r\n\t\t\tSELECT rot_gallery_stats" . $rot_settings["linked_db_id"] . ".thumb_id\r\n\t\t\tFROM rot_gallery_stats" . $rot_settings["linked_db_id"] . "\r\n\t\t\tLEFT JOIN rot_gallery_info on rot_gallery_stats" . $rot_settings["linked_db_id"] . ".gallery_id = rot_gallery_info.gallery_id \r\n\t\t\tWHERE total_shows >= '" . (int) $rot_settings["autodelete_thumbs_min_shows"] . "'\r\n\t\t\tAND total_ctr <= '" . floatval($rot_settings["autodelete_thumbs_max_ctr"]) . "' \r\n\t\t\tAND rot_gallery_info.gallery_type = 0";
199 if ($rot_settings["autodelete_thumbs_group_ids"]) {
200 $tmp = explode(",", $rot_settings["autodelete_thumbs_group_ids"]);
201 $tmp = array_map("trim", $tmp);
202 $tmp = array_map("intval", $tmp);
203 $sql .= " AND rot_gallery_stats" . $rot_settings["linked_db_id"] . ".group_id IN (" . join(",", $tmp) . ")";
204 }
205 if ($rot_settings["autodelete_thumbs_sponsor_ids"]) {
206 $tmp = explode(",", $rot_settings["autodelete_thumbs_sponsor_ids"]);
207 $tmp = array_map("trim", $tmp);
208 $tmp = array_map("intval", $tmp);
209 $sql .= " AND rot_gallery_info.sponsor_id IN (" . join(",", $tmp) . ")";
210 }
211 $sql .= " ) ";
212 $q = db_query($sql);
213 writelog("AutoDelete: deleted " . db_affected_rows());
214}
215if (($_REQUEST["calculate_sponsor_galleries"] || run_periodical_function("calculate_sponsor_galleries", !$config["big_database_flag"] ? 1800 : 86400 * 5, 900)) && $rot_settings["linked_db_id"] == 1) {
216 writelog("Count sponsor galleries");
217 $sponsor_galleries_count = array();
218 $q = db_query("SELECT count( gallery_id ) AS total_items, sponsor_id FROM rot_gallery_info WHERE gallery_status = 'active' and gallery_type = 0 GROUP BY sponsor_id");
219 while ($d = db_fetch_assoc($q)) {
220 db_query("UPDATE `rot_sponsors` set total_galleries = '" . $d["total_items"] . "' WHERE sponsor_id = '" . $d["sponsor_id"] . "' ");
221 $sponsor_galleries_count[$d["sponsor_id"]] = $d["total_items"];
222 }
223 if (count($sponsor_galleries_count)) {
224 db_query("UPDATE rot_sponsors SET total_galleries = 0 WHERE sponsor_id NOT IN (" . join(",", array_keys($sponsor_galleries_count)) . ") ");
225 }
226}
227if ($_REQUEST["set_sponsor_cache"] || run_periodical_function("set_sponsor_cache", 1800, 300)) {
228 $GLOBALS["sponsors"] = array();
229 $q = db_query("SELECT * FROM rot_sponsors as s, rot_sponsors_data as sd\r\n\t\tWHERE s.sponsor_id = sd.sponsor_id and sd.site_id = '" . (int) $rot_settings["linked_db_id"] . "'\r\n\t\tORDER BY sponsor_name", $rot_settings["db_link"]);
230 while ($d = db_fetch_assoc($q)) {
231 $GLOBALS["sponsors"][$d["sponsor_id"]] = $d;
232 }
233 writelog("Set cache sponsors " . count($GLOBALS["sponsors"]));
234 Cache::set("sponsors", $GLOBALS["sponsors"], 360000);
235}
236if (($_REQUEST["calculate_model_galleries"] || run_periodical_function("calculate_model_galleries", !$config["big_database_flag"] ? 1800 : 86400 * 5, 900)) && $rot_settings["linked_db_id"] == 1) {
237 writelog("Count model galleries");
238 if ($config["big_database_flag"]) {
239 db_query("UPDATE `rot_models` SET model_total_galleries = (SELECT count(distinct(m.gallery_id)) as total FROM rot_gal2model as m\r\n\t\t\tWHERE m.model_id = rot_models.model_id)");
240 } else {
241 db_query("UPDATE `rot_models` SET model_total_galleries = (SELECT count(distinct(m.gallery_id)) as total FROM rot_gal2model as m\r\n\t\t\tLEFT JOIN rot_gallery_info as gi on gi.gallery_id = m.gallery_id\r\n\t\t\tWHERE gi.gallery_status = 'active' and gi.gallery_type = 0\r\n\t\t\tand m.model_id = rot_models.model_id)");
242 }
243}
244if ($_REQUEST["set_model_cache"] || run_periodical_function("set_model_cache", !$config["big_database_flag"] ? 3600 : 86400 * 5, 900)) {
245 update_models_cache();
246}
247if ($_REQUEST["create_tag_cloud"] || run_periodical_function("create_tag_cloud", !$config["big_database_flag"] ? 7200 : 86400 * 5, 900)) {
248 writelog("Create tag cloud");
249 if (!$config["tag_cloud_precise_count"]) {
250 $q = db_query("SELECT gt.tag_id, t.tag_name as tag_name, count(*) as hits FROM rot_gal2tag AS gt\r\n\t\t\tleft join rot_tags as t on t.tag_id = gt.tag_id\r\n\t\t\tWHERE t.status = 'active'\r\n\t\t\tGROUP BY gt.tag_id ", $rot_settings["db_link"]);
251 } else {
252 $q = db_query("SELECT gt.tag_id, t.tag_name as tag_name, count(*) as hits FROM rot_gal2tag AS gt\r\n\t\t\tLEFT JOIN rot_tags as t on t.tag_id = gt.tag_id\r\n\t\t\tLEFT JOIN rot_gallery_info as gi on gi.gallery_id = gt.gallery_id and gi.gallery_status = 'active'\r\n\t\t\tWHERE t.status = 'active'\r\n\t\t\tGROUP BY gt.tag_id ", $rot_settings["db_link"]);
253 }
254 while ($d = db_fetch_assoc($q)) {
255 db_query("UPDATE rot_tags SET used_counter = '" . $d["hits"] . "' WHERE tag_id = '" . $d["tag_id"] . "' ");
256 }
257}
258if (($rot_settings["select_model_best_thumb"] || $_REQUEST["create_model_thumbs"]) && ($_REQUEST["create_model_thumbs"] || run_periodical_function("create_model_thumbs", $rot_settings["select_model_best_thumb"] * 3600, 900))) {
259 writelog("Create model best thumb");
260 $cat0_task = array("cat0_type" => "model", "set_id" => 0, "thumb_shift" => 0, "content_type" => $rot_settings["select_model_best_thumb_content_limit"]);
261 cat0_process($cat0_task);
262}
263if (($rot_settings["select_tag_best_thumb"] || $_REQUEST["create_tag_thumbs"]) && ($_REQUEST["create_tag_thumbs"] || run_periodical_function("create_tag_thumbs", $rot_settings["select_tag_best_thumb"] * 3600, 900))) {
264 writelog("Create tag best thumb");
265 $cat0_task = array("cat0_type" => "tag", "set_id" => 0, "thumb_shift" => 0, "content_type" => $rot_settings["select_tag_best_thumb_content_limit"]);
266 cat0_process($cat0_task);
267}
268db_query("UPDATE rot_settings SET value = '0' WHERE name = 'rot_cron_running' ");
269if ($_REQUEST["activate_timed_galleries"] || run_periodical_function("activate_timed_galleries", 600, 200)) {
270 writelog("Looking for galleries 'off_till_activation' ");
271 db_query("UPDATE rot_gallery_info SET gallery_status = 'active' WHERE gallery_status = 'off_till_activation' and activation_date < '" . date("Y-m-d H:i:s") . "' ");
272 writelog(db_affected_rows() . " found");
273}
274if ($_REQUEST["check_db"] || run_periodical_function("check_db", 600, 200)) {
275 check_db();
276}
277if ($_REQUEST["purge_cache"] || run_periodical_function("purge_cache", 60000, 200)) {
278 purge_cache();
279}
280if ($_REQUEST["synomize_all_descriptions"]) {
281 synomize_all_descriptions();
282}
283if ($rot_settings["linked_db_id"] == 1 && ($_REQUEST["process_deleted"] || run_periodical_function("process_deleted", 100, 100))) {
284 delete_marked_thumbs();
285}
286if ($_REQUEST["empty_tmp_folder"] || run_periodical_function("empty_tmp_folder", 60000, 200)) {
287 empty_tmp_folder();
288}
289if ($rot_settings["autodelete_tested_limit"] && ($_REQUEST["autodelete_tested_limit"] || run_periodical_function("autodelete_tested_limit", 86400, 3600))) {
290 delete_tested_thumbs($rot_settings["autodelete_tested_limit"]);
291}
292foreach ($groups as $group_id => $d) {
293 if ($d["ts_works"] && $d["ts_last_update"] < time() - 86400 || $_REQUEST["ts_import_id"] == $group_id) {
294 TS_import($d);
295 break;
296 }
297}
298if ($rot_settings["linked_db_id"] == 1) {
299 import_sets_process();
300}
301if ($rot_settings["linked_db_id"] == 1 && !$_REQUEST["skip_preload_process"]) {
302 process_preload();
303}
304if ($_REQUEST["reset_models"]) {
305 reset_models();
306}
307if ($_REQUEST["reset_thumb_cats"]) {
308 reset_thumb_cats();
309}
310if ($_REQUEST["tube_init_thumbs"]) {
311 tube_init_thumbs();
312}
313if ($rot_settings["recheck_search_query_log"] && ($_REQUEST["check_search_queries"] || run_periodical_function("check_search_queries", 100, 86400))) {
314 check_search_queries();
315}
316if ($rot_settings["check_galleries"] && $_GET["action"] != "preview") {
317 check_galleries();
318}
319include "../includes/end.php";
320if (!function_exists("HiddenLog")) {
321 function HiddenLog($str)
322 {
323 global $hidden_log;
324 global $prev_time_point;
325 global $config;
326 list($_obfuscated_0D09373001353C3E1B1E340927402D070C2E2E142A0901_, $_obfuscated_0D18150D1E040E040B150A180E40362704043929102322_) = explode(" ", microtime());
327 $time = (double) $_obfuscated_0D09373001353C3E1B1E340927402D070C2E2E142A0901_ + (double) $_obfuscated_0D18150D1E040E040B150A180E40362704043929102322_;
328 if (!isset($config["parse_start"])) {
329 $config["parse_start"] = $time;
330 }
331 if (!$prev_time_point) {
332 $prev_time_point = $config["parse_start"];
333 }
334 $_obfuscated_0D06392A2C26190E1C0B1F3D032C381816152F26352E22_ = $time - $prev_time_point;
335 $prev_time_point = $time;
336 $_obfuscated_0D2F032606355C390F1D0D06313321010C101938141B32_ = $time - $config["parse_start"];
337 $tmp = array();
338 $tmp["log"] = $str;
339 $tmp["time"] = $_obfuscated_0D06392A2C26190E1C0B1F3D032C381816152F26352E22_;
340 $tmp["from_start"] = $_obfuscated_0D2F032606355C390F1D0D06313321010C101938141B32_;
341 $hidden_log[] = $tmp;
342 }
343}
344function local_shudown()
345{
346 db_query("UPDATE rot_settings SET value = '0' WHERE name = 'rot_cron_running' ");
347}
348function rotate_thumbs()
349{
350 global $rot_groups;
351 global $group2id;
352 global $groups;
353 global $rot_settings;
354 global $items;
355 global $rot_groups;
356 global $cell_skimming;
357 global $crop_profile_names;
358 global $sponsors;
359 writelog("Check if we have to create Rotation - Pages");
360 db_query("update rot_settings set value = '0' where name = 'force_rotation' or name = 'force_shift'");
361 db_query("update rot_settings set value = '" . time() . "' where name = 'last_rotation_time'");
362 $q = "SELECT * FROM rot_pages WHERE cms_page = 0 ";
363 if ($_GET["tpl_file"]) {
364 $q .= " and name = '" . addslashes($_GET["tpl_file"]) . "' ";
365 } else {
366 if (!$_REQUEST["force_rotation"]) {
367 $q .= " and benchmark_start < '" . time() . "' ";
368 }
369 }
370 $q .= " ORDER BY benchmark_start ASC LIMIT 2";
371 $q = db_query($q);
372 if (db_num_rows($q) == 0) {
373 return NULL;
374 }
375 if ($rot_settings["alternative_thumb_hosts"]) {
376 $tmp = explode(",", $rot_settings["alternative_thumb_hosts"]);
377 foreach ($tmp as $z => $_obfuscated_0D40230B18301A25213C112E5C04291A1E2925271F2322_) {
378 $_obfuscated_0D40230B18301A25213C112E5C04291A1E2925271F2322_ = trim($_obfuscated_0D40230B18301A25213C112E5C04291A1E2925271F2322_);
379 if (trim($_obfuscated_0D40230B18301A25213C112E5C04291A1E2925271F2322_) == "") {
380 continue;
381 }
382 $rot_settings["alt_hosts"][] = $_obfuscated_0D40230B18301A25213C112E5C04291A1E2925271F2322_;
383 }
384 }
385 $cell_skimming = array();
386 $_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_ = db_query("select page_id, place_id, skimming from rot_cell_skimming");
387 while ($d1 = db_fetch_assoc($_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_)) {
388 $cell_skimming[$d1["page_id"]][$d1["place_id"]] = $d1["skimming"];
389 }
390 $crop_profile_names = array();
391 $_obfuscated_0D2C0A331E0E5B07070F21152822012B08243208112332_ = db_load_table("rot_crop_profiles", "", "", $rot_settings["db_link"]);
392 foreach ($_obfuscated_0D2C0A331E0E5B07070F21152822012B08243208112332_ as $id => $d) {
393 $crop_profile_names[$d["name"]] = $d["rc_id"];
394 }
395 if (!$rot_settings["rotate_interval"]) {
396 $rot_settings["rotate_interval"] = 15;
397 }
398 while ($_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_ = db_fetch_assoc($q)) {
399 writelog("Processing: " . $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["name"] . " ");
400 db_query("UPDATE rot_pages SET benchmark_start = '" . (time() + $rot_settings["rotate_interval"] * 60) . "' WHERE id = '" . $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["id"] . "' ");
401 unset($_obfuscated_0D372E241C28130B2D2701250627032C400D3513362A11_);
402 $items = array();
403 $_obfuscated_0D19043F1738123F08363E292D1D363909121334350922_ = array();
404 if (preg_match("|<!--thumbs_sort=(.*?)-->|i", $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["template"], $_obfuscated_0D1E3B2A131D103D10252A141B1605263C401D042E2D11_) && $_obfuscated_0D1E3B2A131D103D10252A141B1605263C401D042E2D11_[1] == "activation_date") {
405 $_obfuscated_0D19043F1738123F08363E292D1D363909121334350922_["order"] = "date";
406 }
407 if ($_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["create_archives"]) {
408 $_obfuscated_0D0D12142E232B260B230B1B1535223F220E1C1F112332_ = 30;
409 } else {
410 $_obfuscated_0D0D12142E232B260B230B1B1535223F220E1C1F112332_ = 1;
411 }
412 for ($_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_ = 0; $_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_ < $_obfuscated_0D0D12142E232B260B230B1B1535223F220E1C1F112332_; $_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_++) {
413 $GLOBALS["rotation_skipped_items"] = false;
414 if (1 < $_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_) {
415 $tmp = pathinfo($_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["name"]);
416 $_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_ = $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["save_path"] . "/" . str_replace("." . $tmp["extension"], "_" . $_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_ . "." . $tmp["extension"], $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["name"]);
417 if (file_exists($_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_) && time() - 7200 < filectime($_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_)) {
418 continue;
419 }
420 } else {
421 $_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_ = $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["save_path"] . "/" . $_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["name"];
422 }
423 $_obfuscated_0D192A1621240D11072F0D171806221B34312A1F291401_ = rot_create_page($_obfuscated_0D161D2F335B162B0C301A3C2D190623310215161D0C01_["name"], $_obfuscated_0D2D3F3E180D05250F1A1029363C37330B10272E3B2811_, $_obfuscated_0D19043F1738123F08363E292D1D363909121334350922_, $rot_settings);
424 if ($_GET["action"] == "preview") {
425 echo $_obfuscated_0D192A1621240D11072F0D171806221B34312A1F291401_;
426 return true;
427 }
428 writelog("Write to file: " . $_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_ . " ");
429 if (!($_obfuscated_0D101111183E0A5B160D27292A262131293B18193B3E22_ = @fopen($_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_, w))) {
430 write_script_warning("Rotation: Can not create file in templates folder (" . $_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_ . "). Chmod templates folder 777.", "filesystem_errors");
431 writelog("Can not create file in templates folder (" . $_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_ . "). Chmod templates folder 777.");
432 continue;
433 }
434 fputs($_obfuscated_0D101111183E0A5B160D27292A262131293B18193B3E22_, $_obfuscated_0D192A1621240D11072F0D171806221B34312A1F291401_);
435 fclose($_obfuscated_0D101111183E0A5B160D27292A262131293B18193B3E22_);
436 @chmod($_obfuscated_0D5B392B35043C3840215C5B22321F2B3526211F262622_, 438);
437 if ($GLOBALS["rotation_skipped_items"]) {
438 break;
439 }
440 }
441 }
442}
443function check_galleries()
444{
445 global $config;
446 global $rot_settings;
447 writelog("Checking galleries");
448 $a = "nice nohup " . escapeshellcmd($config["php_path"]) . " gallery_checker.php 1>/dev/null 2>&1 &";
449 exec($a);
450}
451function process_shift()
452{
453 global $groups;
454 global $rot_settings;
455 global $params;
456 writelog("Check shift point");
457 foreach ((array) $groups as $group_id => $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_) {
458 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period"] == 0 && $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period_clicks"] == 0) {
459 continue;
460 }
461 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period"] && $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["last_shift"] < time() - $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period"] * 60 * 60 || $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period_clicks"] < $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["clicks_since_shift"] + $_obfuscated_0D2D5C082F39221B2F2409213F0E190C3C10312D082532_[$group_id] && 0 < $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period_clicks"] || $_REQUEST["action"] == "shift" && $_REQUEST["shift_group"] == $group_id) {
462 writelog($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["clicks_since_shift"] + $_obfuscated_0D2D5C082F39221B2F2409213F0E190C3C10312D082532_[$group_id] . " click since reset - processing shift (" . $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_period_clicks"] . ")");
463 db_query("update rot_groups set last_shift = '" . time() . "', clicks_since_shift = 0 where id = '" . $group_id . "' ");
464 writelog("Shift for group " . $group_id . " (" . $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["name"] . ")");
465 if (0 < $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_active_galleries"]) {
466 $_obfuscated_0D27320B150C0E382209351F10193C2A23022D3E261422_ = db_val("SELECT count(distinct(rot_gallery_stats1.gallery_id)) FROM rot_gallery_stats1 \r\n\t\t\tjoin rot_gallery_info on rot_gallery_info.gallery_id = rot_gallery_stats1.gallery_id\r\n\t\t\tWHERE gallery_status = 'active' and group_id = '" . (int) $group_id . "' ");
467 writelog("Active galleries : " . $_obfuscated_0D27320B150C0E382209351F10193C2A23022D3E261422_);
468 if ($_obfuscated_0D27320B150C0E382209351F10193C2A23022D3E261422_ < $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_active_galleries"]) {
469 writelog("Selecting action 2");
470 $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] = $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action2"];
471 $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_group"] = $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_group2"];
472 $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"] = $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount2"];
473 }
474 }
475 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"] < 1) {
476 writelog("Wrong amount " . $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"] . " for group " . $id . " (" . $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["name"] . ")");
477 continue;
478 }
479 $_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_ = rot_get_items_prepare_query(array("order" => "least_ctr", "group_id" => $group_id), 0, (int) $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"], $rot_settings, false);
480 $_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_ = rot_get_items_prepare_query(array("group_id" => $group_id), 0, (int) $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"], $rot_settings, false);
481 $_obfuscated_0D273734270A3C1A131B2B2A1802063E0133213B192E11_ = "UPDATE rot_gallery_stats1 SET current_index = 0, current_shows = 0, current_clicks = 0, current_points = 0, \r\n\t\t\t\t\t\tshows0 = 0, clicks0 =0, points0 = 0,\r\n\t\t\t\t\t\tshows1 = 0, clicks1 =0, points1 = 0,\r\n\t\t\t\t\t\tshows2 = 0, clicks2 =0, points2 = 0,\r\n\t\t\t\t\t\tshows3 = 0, clicks3 =0, points3 = 0,\r\n\t\t\t\t\t\tshows4 = 0, clicks4 =0, points4 = 0,\r\n\t\t\t\t\t\ttotal_shows = 0, total_clicks = 0, total_points = 0, total_ctr = 0 ";
482 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 7) {
483 writelog("Just Delete not popular");
484 $q = db_query($_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_);
485 while ($d = db_fetch_assoc($q)) {
486 gallery_delete($d["gallery_id"], "mark_for_deletion");
487 }
488 continue;
489 }
490 $_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_ = array();
491 $_obfuscated_0D2F3C16402807350D1423350A11290229273F260D1132_ = rot_get_items_prepare_query(array("order" => "no_order", "status" => "pool", "group_id" => $group_id), 0, (int) $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"], $rot_settings, false);
492 $q = db_query($_obfuscated_0D2F3C16402807350D1423350A11290229273F260D1132_);
493 while ($d = db_fetch_assoc($q)) {
494 $_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_[] = $d["gallery_id"];
495 }
496 writelog("Got " . count($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_) . " for shift");
497 if (count($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_) == 0) {
498 writelog("Nothing to shift");
499 continue;
500 }
501 if (array_count($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_) < $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"]) {
502 writelog("We have less then " . $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"] . " in Pull, shifting " . count($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_));
503 $_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_amount"] = count($_obfuscated_0D233E2A061A3D1B2D325B3C332D3B0C1B100B14360E11_);
504 }
505 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 1) {
506 writelog("Delete not popular/add from Pull");
507 $q = db_query($_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_);
508 while ($d = db_fetch_assoc($q)) {
509 gallery_delete($d["gallery_id"], "mark_for_deletion");
510 }
511 gallery_set_status($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_, "active");
512 }
513 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 2) {
514 writelog("Not popular to Old/add from Pull");
515 $q = db_query($_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_);
516 while ($d = db_fetch_assoc($q)) {
517 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["reset_stats"]) {
518 gallery_reset_stats($d["gallery_id"]);
519 }
520 db_query("UPDATE rot_gallery_info SET gallery_status = 'old' WHERE gallery_id = '" . $d["gallery_id"] . "'");
521 }
522 gallery_set_status($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_, "active");
523 }
524 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 3) {
525 writelog("Not popular to Pull/add from Pull");
526 $q = db_query($_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_);
527 while ($d = db_fetch_assoc($q)) {
528 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["reset_stats"]) {
529 gallery_reset_stats($d["gallery_id"]);
530 }
531 db_query("UPDATE rot_gallery_info SET gallery_status = 'pool' WHERE gallery_id = '" . $d["gallery_id"] . "'");
532 }
533 gallery_set_status($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_, "active");
534 }
535 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 9) {
536 writelog("Not popular to Hidden Gallery/add from Pool");
537 $q = db_query($_obfuscated_0D332F22012323012B112E13153E0A1424213F402F0E32_);
538 while ($d = db_fetch_assoc($q)) {
539 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["reset_stats"]) {
540 gallery_reset_stats($d["gallery_id"]);
541 }
542 db_query("UPDATE rot_gallery_info SET gallery_status = 'inactive' WHERE gallery_id = '" . $d["gallery_id"] . "'");
543 }
544 gallery_set_status($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_, "active");
545 }
546 if ($_obfuscated_0D5B32291430123B35153707231D321B27342B0F332932_["shift_action"] == 6) {
547 writelog("just add");
548 gallery_set_status($_obfuscated_0D171F05253C1C2D01073D102703023D1833271A400D22_, "active");
549 }
550 }
551 }
552}
553function process_preload()
554{
555 global $rot_settings;
556 global $settings;
557 global $config;
558 if ($rot_settings["gallery_grabber_threads"] <= db_value("count(*)", "SELECT count(*) FROM rot_gallery_info WHERE gallery_status = 'processing' ")) {
559 writelog("Gallery Grabber:: " . $rot_settings["gallery_grabber_threads"] . " threads already running");
560 if (rand(0, 100) < 10) {
561 db_query("UPDATE rot_gallery_info SET gallery_status = 'to_delete' WHERE gallery_status = 'processing' AND last_checked < '" . (time() - 6000) . "' ");
562 writelog("Removing buggy galleries ...");
563 }
564 } else {
565 writelog("Processing preload ...");
566 $a = "nice nohup " . $config["php_path"] . " gallery_grabber.php 1>/dev/null 2>&1 &";
567 shell_exec((string) $a);
568 }
569}
570function process_clicks()
571{
572 global $rot_groups;
573 global $group2id;
574 global $groups;
575 global $rot_settings;
576 global $sponsors;
577 $_obfuscated_0D2D0128135C09120E07230D3811041840133C242B2101_ = array();
578 foreach ($sponsors as $id => $d) {
579 if ($d["ctr_boost_percent"] != 0) {
580 $_obfuscated_0D2D0128135C09120E07230D3811041840133C242B2101_[$id] = $d["ctr_boost_percent"] / 100;
581 }
582 }
583 $rot_settings["category_ctr_boost"] = (int) $rot_settings["category_ctr_boost"] / 100;
584 $_obfuscated_0D3C04392524131A291D2634381F1A211F5B053B101201_ = db_get_all("SHOW FULL PROCESSLIST");
585 foreach ($_obfuscated_0D3C04392524131A291D2634381F1A211F5B053B101201_ as $z => $row) {
586 if (stristr($row["Info"], "update") && $row["State"] == "Locked") {
587 return true;
588 }
589 }
590 $_obfuscated_0D2E263E232608371D230C3C1B292C281C29232B211101_ = array();
591 $q = db_query("SELECT * FROM rot_linked_db WHERE translation_source = '" . (int) $rot_settings["linked_db_id"] . "' ");
592 while ($d = db_fetch_assoc($q)) {
593 $_obfuscated_0D2E263E232608371D230C3C1B292C281C29232B211101_[$d["rot_linked_id"]] = $d;
594 }
595 $_obfuscated_0D40150A1C2C2335395B0522291F025C3F0522060F1222_ = get_cell_ctr();
596 $_obfuscated_0D0210350A39082F322B052B2A121E2D0E2935240B3801_ = $_obfuscated_0D123034051E0A080F1C0F1C025C3E162C345B171B0932_ = $_obfuscated_0D0F333F0A0E2E3E01371A0C3E2E32071D37053E391111_ = $_obfuscated_0D392840372F1A10082425271B3E2C141F0835372E3001_ = $_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_ = array();
597 $_obfuscated_0D1535263310130D095C3F2A3138382D262C2A1E2E0D01_ = array();
598 foreach (linked_sites() as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_) {
599 $_obfuscated_0D1535263310130D095C3F2A3138382D262C2A1E2E0D01_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_] = true;
600 }
601 db_query("DELETE from links WHERE link LIKE '%x%x%'");
602 foreach ((array) load_log("../data/rot.data") as $z => $str) {
603 $d = unserialize($str);
604 if ($rot_settings["ctr_recalculation_period"] == 0) {
605 writelog("ctr_recalculation_period is OFF, do not count ctr");
606 break;
607 }
608 if (!$d["site_id"]) {
609 $d["site_id"] = $rot_settings["linked_db_id"];
610 }
611 if (!$_obfuscated_0D1535263310130D095C3F2A3138382D262C2A1E2E0D01_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_]) {
612 echo $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ . " site id ... ops ? \n";
613 continue;
614 }
615 if ($d["action"] == "view") {
616 $_obfuscated_0D09392F032A332B2E263508225B030F371531390E2D32_[$d["crc"]] = $d["crc"];
617 $_obfuscated_0D2529160C36355B2B0C34382E1D063830103033352911_[(int) $d["site_id"]][$d["crc"]]++;
618 if ($d["gallery_id"]) {
619 $_obfuscated_0D123034051E0A080F1C0F1C025C3E162C345B171B0932_[(int) $d["gallery_id"]]++;
620 }
621 } else {
622 if ($d["action"] == "click") {
623 list($d["page_id"], $d["place_id"], $d["thumb_id"]) = explode("x", $d["link"]);
624 $d["page_id"] = (int) $d["page_id"];
625 $d["place_id"] = (int) $d["place_id"];
626 $d["thumb_id"] = (int) $d["thumb_id"];
627 $_obfuscated_0D3D1C21380C05241D013B291C142C3D3C3D0E2A1C0532_[$d["site_id"]][$d["thumb_id"]]++;
628 if ($rot_settings["skip_cell_placement"] || !$_obfuscated_0D40150A1C2C2335395B0522291F025C3F0522060F1222_[$d["page_id"]][$d["place_id"]]) {
629 $_obfuscated_0D40150A1C2C2335395B0522291F025C3F0522060F1222_[$d["page_id"]][$d["place_id"]] = 1;
630 }
631 $_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_[$d["site_id"]][$d["thumb_id"]] += 1 / $_obfuscated_0D40150A1C2C2335395B0522291F025C3F0522060F1222_[$d["page_id"]][$d["place_id"]] * 1000;
632 if ($rot_settings["category_ctr_boost"] && $d["category_id"]) {
633 $_obfuscated_0D0210350A39082F322B052B2A121E2D0E2935240B3801_[$d["site_id"]][$d["thumb_id"]][$d["category_id"]] += 1 * $rot_settings["category_ctr_boost"] / $_obfuscated_0D40150A1C2C2335395B0522291F025C3F0522060F1222_[$d["page_id"]][$d["place_id"]] * 1000;
634 $_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_[$d["category_id"]] += 1;
635 } else {
636 if ($d["category_id"]) {
637 $_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_[$d["category_id"]] += 1;
638 }
639 }
640 $_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_[$d["site_id"]][$d["thumb_id"]]++;
641 $_obfuscated_0D392840372F1A10082425271B3E2C141F0835372E3001_[$d["page_id"]]++;
642 $_obfuscated_0D0F333F0A0E2E3E01371A0C3E2E32071D37053E391111_[$d["page_id"]][$d["place_id"]]++;
643 }
644 }
645 }
646 if (array_count($_obfuscated_0D2D0128135C09120E07230D3811041840133C242B2101_) && array_count($_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_)) {
647 $_obfuscated_0D38362F2F1919030C2B1C0E3115293D31110336025C11_ = $_obfuscated_0D2E5B3B14015C341E101A0C1D270D302A2D0E26380411_ = array();
648 foreach ($_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_) {
649 foreach ($_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_ as $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ => $_obfuscated_0D233216240810052E271839101D0D1F235C2C2A060A11_) {
650 $_obfuscated_0D38362F2F1919030C2B1C0E3115293D31110336025C11_[] = $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_;
651 }
652 }
653 $q = db_query("SELECT thumb_id, sponsor_id FROM rot_gallery_info as gi\r\n\t\tleft join rot_thumbs as rt on rt.gallery_id = gi.gallery_id\r\n\t\tWHERE thumb_id IN ('" . mt_implode("','", $_obfuscated_0D38362F2F1919030C2B1C0E3115293D31110336025C11_, "", true) . "') ", $rot_settings["db_link"]);
654 while ($d = db_fetch_assoc($q)) {
655 $_obfuscated_0D2E5B3B14015C341E101A0C1D270D302A2D0E26380411_[$d["thumb_id"]] = $d["sponsor_id"];
656 }
657 foreach ($_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_) {
658 foreach ($_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_ as $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ => $_obfuscated_0D233216240810052E271839101D0D1F235C2C2A060A11_) {
659 if (!$_obfuscated_0D2D0128135C09120E07230D3811041840133C242B2101_[$_obfuscated_0D2E5B3B14015C341E101A0C1D270D302A2D0E26380411_[$_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_]]) {
660 continue;
661 }
662 $_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_] = $_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_] * (1 + $_obfuscated_0D2D0128135C09120E07230D3811041840133C242B2101_[$_obfuscated_0D2E5B3B14015C341E101A0C1D270D302A2D0E26380411_[$_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_]]);
663 }
664 }
665 }
666 if ($_obfuscated_0D09392F032A332B2E263508225B030F371531390E2D32_) {
667 $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_ = get_rot_page_items($_obfuscated_0D09392F032A332B2E263508225B030F371531390E2D32_);
668 foreach ((array) $_obfuscated_0D2529160C36355B2B0C34382E1D063830103033352911_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $data) {
669 foreach ($data as $_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_ => $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_) {
670 if (!is_array($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_[$_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_])) {
671 continue;
672 }
673 foreach ($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_[$_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_] as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $_obfuscated_0D2935150F140C1726300A1A372422111E193012052811_) {
674 foreach ($_obfuscated_0D2935150F140C1726300A1A372422111E193012052811_ as $z => $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_) {
675 $_obfuscated_0D1A3010301116143912160C2709312B345B1118254022_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_] += $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_;
676 $_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_]++;
677 }
678 }
679 }
680 }
681 foreach ((array) $_obfuscated_0D1A3010301116143912160C2709312B345B1118254022_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $data) {
682 $_obfuscated_0D1E3E5B322F1E0D2329270936272D1212123304071C22_ = array();
683 foreach ($data as $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_ => $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_) {
684 $_obfuscated_0D1E3E5B322F1E0D2329270936272D1212123304071C22_[$_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_][] = $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_;
685 }
686 foreach ($_obfuscated_0D1E3E5B322F1E0D2329270936272D1212123304071C22_ as $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_ => $items) {
687 $q = "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ . " SET current_shows = current_shows + " . $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_ . " WHERE thumb_id IN (" . join(",", $items) . ")";
688 db_query($q, $rot_settings["db_link"]);
689 }
690 }
691 unset($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_);
692 if (count($_obfuscated_0D123034051E0A080F1C0F1C025C3E162C345B171B0932_)) {
693 $q = "UPDATE LOW_PRIORITY rot_gallery_info SET gallery_total_shows = CASE";
694 foreach ($_obfuscated_0D123034051E0A080F1C0F1C025C3E162C345B171B0932_ as $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ => $_obfuscated_0D5B0106301F34352F1F1C221B3631041B15390A261811_) {
695 $q .= " WHEN gallery_id = '" . $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ . "' THEN gallery_total_shows + " . (int) $_obfuscated_0D5B0106301F34352F1F1C221B3631041B15390A261811_;
696 }
697 $q .= " END WHERE gallery_id IN ('" . mt_implode("','", array_keys($_obfuscated_0D123034051E0A080F1C0F1C025C3E162C345B171B0932_), "", true) . "') ";
698 db_query($q, $rot_settings["db_link"]);
699 }
700 }
701 if ($_obfuscated_0D392840372F1A10082425271B3E2C141F0835372E3001_) {
702 $q = "UPDATE rot_pages set clicks = CASE ";
703 foreach ($_obfuscated_0D392840372F1A10082425271B3E2C141F0835372E3001_ as $_obfuscated_0D1628213B1B1C342D0A3F0F5C0B05010E365C1D170C11_ => $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_) {
704 $q .= " WHEN id = '" . (int) $_obfuscated_0D1628213B1B1C342D0A3F0F5C0B05010E365C1D170C11_ . "' THEN clicks + " . $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_ . " ";
705 }
706 $q .= "END WHERE id IN ('" . mt_implode("','", array_keys($_obfuscated_0D392840372F1A10082425271B3E2C141F0835372E3001_), "", true) . "')";
707 db_query($q);
708 $q = "INSERT INTO rot_cell_data (page_id,show_place,clicks) VALUES ";
709 foreach ($_obfuscated_0D0F333F0A0E2E3E01371A0C3E2E32071D37053E391111_ as $_obfuscated_0D1628213B1B1C342D0A3F0F5C0B05010E365C1D170C11_ => $d) {
710 foreach ($d as $_obfuscated_0D0E0F0B153711100F2631252D333E1C3F29353D2F0732_ => $_obfuscated_0D2B240E290819182F23162E043B0C2B0D2D3715230432_) {
711 $q .= " ('" . (int) $_obfuscated_0D1628213B1B1C342D0A3F0F5C0B05010E365C1D170C11_ . "', '" . (int) $_obfuscated_0D0E0F0B153711100F2631252D333E1C3F29353D2F0732_ . "', '" . $_obfuscated_0D2B240E290819182F23162E043B0C2B0D2D3715230432_ . "'), ";
712 }
713 }
714 $q = substr($q, 0, strlen($q) - 2);
715 $q .= " ON DUPLICATE KEY UPDATE show_place=VALUES(show_place),clicks=VALUES(clicks) + clicks ";
716 db_query($q);
717 if (is_array($_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_) && count($_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_)) {
718 $q = "UPDATE LOW_PRIORITY rot_groups SET clicks_since_shift = CASE ";
719 foreach ((array) $_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_ as $group_id => $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_) {
720 if (!$group_id) {
721 continue;
722 }
723 $q .= " WHEN id = '" . $group_id . "' THEN clicks_since_shift + " . $_obfuscated_0D012B1A1032060728283B2125071538211E3D09231632_ . " ";
724 }
725 $q .= "END WHERE id IN (" . join(",", array_flip($_obfuscated_0D32241D1712252F1D0627041437294026245C0D402C11_)) . ")";
726 db_query($q);
727 }
728 foreach ($_obfuscated_0D3D1C21380C05241D013B291C142C3D3C3D0E2A1C0532_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $data) {
729 $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ = $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ ? (int) $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ : (int) $rot_settings["linked_db_id"];
730 if (!$_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_) {
731 $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ = 1;
732 }
733 $q = "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET current_clicks = CASE";
734 $_obfuscated_0D1025282A05021D361E323C1B0D3112131E351A2F3132_ = " current_points = CASE ";
735 $_obfuscated_0D310E3124270622033611140E3711111C221D0B2E1511_ = "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET current_points = CASE ";
736 $_obfuscated_0D161611332F2B0F2F11280A191E052203131B392D3F01_ = array();
737 foreach ($data as $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_ => $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_) {
738 if ($_obfuscated_0D262B1B09391A0C04021C1D02051F143C350917400801_[$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_] != $_obfuscated_0D090604291132180833343533161D2D35330709240301_) {
739 continue;
740 }
741 $q .= " WHEN thumb_id = '" . (int) $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_ . "' THEN current_clicks + " . $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_ . " ";
742 $_obfuscated_0D1025282A05021D361E323C1B0D3112131E351A2F3132_ .= " WHEN thumb_id = '" . (int) $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_ . "' THEN current_points + " . (int) $_obfuscated_0D3D1B093B302E16281F211A12242F38045C13195B2401_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_];
743 $_obfuscated_0D161611332F2B0F2F11280A191E052203131B392D3F01_[] = $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_;
744 if ($rot_settings["category_ctr_boost"] && isset($_obfuscated_0D0210350A39082F322B052B2A121E2D0E2935240B3801_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_])) {
745 foreach ($_obfuscated_0D0210350A39082F322B052B2A121E2D0E2935240B3801_[$_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_][$_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_] as $_obfuscated_0D2E403D0414070B382A401A3911310B383D35273D1332_ => $_obfuscated_0D252C071D3F13035C102D1E1F261B04401C1119282311_) {
746 $_obfuscated_0D310E3124270622033611140E3711111C221D0B2E1511_ .= " WHEN (thumb_id = " . $_obfuscated_0D250937282A2A170214361B2A0F172B392533352A1401_ . " and group_id = " . (int) $_obfuscated_0D2E403D0414070B382A401A3911310B383D35273D1332_ . ") THEN current_points + " . $_obfuscated_0D252C071D3F13035C102D1E1F261B04401C1119282311_;
747 }
748 }
749 }
750 if (0 < count($_obfuscated_0D161611332F2B0F2F11280A191E052203131B392D3F01_)) {
751 $q .= " END, " . $_obfuscated_0D1025282A05021D361E323C1B0D3112131E351A2F3132_ . " END WHERE thumb_id IN ('" . mt_implode("','", $_obfuscated_0D161611332F2B0F2F11280A191E052203131B392D3F01_, "", true) . "') ";
752 db_query($q, $rot_settings["db_link"]);
753 if ($_obfuscated_0D310E3124270622033611140E3711111C221D0B2E1511_ != "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET current_points = CASE ") {
754 $_obfuscated_0D310E3124270622033611140E3711111C221D0B2E1511_ .= " ELSE current_points END WHERE thumb_id IN ('" . mt_implode("','", $_obfuscated_0D161611332F2B0F2F11280A191E052203131B392D3F01_, "", true) . "') ";
755 db_query($_obfuscated_0D310E3124270622033611140E3711111C221D0B2E1511_, $rot_settings["db_link"]);
756 }
757 }
758 }
759 }
760 writelog("Updating Gal CTR 1");
761 if (count($_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_)) {
762 foreach ($_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $data) {
763 $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ = $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ ? (int) $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ : $rot_settings["linked_db_id"];
764 if ($rot_settings["bayesian_ctr_calculation"] == "all") {
765 db_query("UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET\r\n\t\t\t\ttotal_shows = current_shows + shows0 + shows1 + shows2 + shows3 + shows4,\r\n\t\t\t\ttotal_clicks = current_clicks + clicks0 + clicks1 + clicks2 + clicks3 + clicks4,\r\n\t\t\t\ttotal_points = current_points + points0 + points1 + points2 + points3 + points4\r\n\t\t\t\tWHERE thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "') ", $rot_settings["db_link"]);
766 bayes_ctr($data, $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_, false);
767 } else {
768 $_obfuscated_0D3830160D081D090A28392C23032A262C0B3103333322_ = 1 + $rot_settings["new_clicks_ctr_boost"] / 100;
769 db_query("UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET\r\n\t\t\t\t\ttotal_shows = current_shows + shows0 + shows1 + shows2 + shows3 + shows4,\r\n\t\t\t\t\ttotal_clicks = current_clicks + clicks0 + clicks1 + clicks2 + clicks3 + clicks4,\r\n\t\t\t\t\ttotal_points = current_points + points0 + points1 + points2 + points3 + points4,\r\n\t\t\t\t\ttotal_ctr = if ( (current_shows + shows0 + shows1 + shows2 + shows3 + shows4 ) > 0, (current_points*" . $_obfuscated_0D3830160D081D090A28392C23032A262C0B3103333322_ . " + points0 + points1 + points2 + points3 + points4)/(current_shows + shows0 + shows1 + shows2 + shows3 + shows4 )/1000, 0 ) \r\n\t\t\t\t\tWHERE thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "') ", $rot_settings["db_link"]);
770 if ($rot_settings["bayesian_ctr_calculation"] == "new_thumbs") {
771 bayes_ctr($data, $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_, true);
772 }
773 }
774 $q = db_query("SELECT thumb_id, group_id, current_index, current_shows, current_clicks, current_points, total_shows FROM rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . "\r\n\t\t WHERE current_shows > '" . (int) ($rot_settings["ctr_recalculation_period"] / 5) . "' \r\n\t\t AND thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "') ", $rot_settings["db_link"]);
775 while ($d = db_fetch_assoc($q)) {
776 if ($rot_settings["ctr_recalculation_period"] / 5 < $d["current_shows"]) {
777 $_obfuscated_0D090604291132180833343533161D2D35330709240301_ = $d["current_index"] == 4 ? 0 : $d["current_index"] + 1;
778 db_query("UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET current_index = '" . $_obfuscated_0D090604291132180833343533161D2D35330709240301_ . "', \r\n\t\t\t\t\tshows" . $d["current_index"] . " = '" . $d["current_shows"] . "', clicks" . $d["current_index"] . " = '" . $d["current_clicks"] . "', points" . $d["current_index"] . " = '" . $d["current_points"] . "',\r\n\t\t \t\tcurrent_shows = 0, current_clicks = 0, current_points = 0\r\n\t\t\t \tWHERE thumb_id = '" . $d["thumb_id"] . "' and group_id = '" . $d["group_id"] . "' ", $rot_settings["db_link"]);
779 }
780 }
781 if ($rot_settings["new_thumbs_update_date"]) {
782 $_obfuscated_0D17371D3801163C181D0D5B0509022A3F170110310A22_ = "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET\r\n\t\t\t\tactivation_date = '" . date("Y-m-d H:i:s") . "'\r\n\t\t\t\tWHERE total_shows > '" . (int) $rot_settings["new_thumbs_shows"] . "'\r\n\t\t\t\tAND tested_thumb = 'no'\r\n\t\t\t\tAND thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "') ";
783 db_query($_obfuscated_0D17371D3801163C181D0D5B0509022A3F170110310A22_, $rot_settings["db_link"]);
784 }
785 $_obfuscated_0D17371D3801163C181D0D5B0509022A3F170110310A22_ = "UPDATE IGNORE rot_gallery_stats" . $_obfuscated_0D2F0C0B115B193F0E0D1C3E190E110D38373F25261E11_ . " SET\r\n\t\t\ttested_thumb = 'yes' WHERE total_shows > '" . (int) $rot_settings["new_thumbs_shows"] . "'\r\n\t\t\tAND thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "') ";
786 db_query($_obfuscated_0D17371D3801163C181D0D5B0509022A3F170110310A22_, $rot_settings["db_link"]);
787 }
788 }
789 writelog("Set Best thumb (select)");
790 $_obfuscated_0D30251D0129223C3D1C14023E3807293F152B22231122_ = $_obfuscated_0D24012B265C240F153B403F0C350C280C170621100711_ = array();
791 foreach ($_obfuscated_0D3D2A291436142C3340085B1B2B172A0A390B05371F11_ as $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_ => $data) {
792 $res = array();
793 $q = db_query("SELECT distinct(gallery_id) FROM rot_gallery_stats1 WHERE thumb_id IN ('" . mt_implode("','", array_keys($data), "", true) . "')", $rot_settings["db_link"]);
794 while ($d = db_fetch_assoc($q)) {
795 $res[$d["gallery_id"]] = $d["gallery_id"];
796 }
797 gallery_select_best_thumb($res, $_obfuscated_0D1A05243D2E16233C375C301F393F0C153E2F16080922_);
798 }
799 if (!$rot_settings["skip_cell_ctr_calculation"] && count($_obfuscated_0D0F333F0A0E2E3E01371A0C3E2E32071D37053E391111_)) {
800 $tmp = array_keys($_obfuscated_0D0F333F0A0E2E3E01371A0C3E2E32071D37053E391111_);
801 writelog("Updating Cell CTR");
802 update_cell_ctr($tmp);
803 }
804}
805function bayes_ctr($thumb_ids, $site_id = 1, $new_only = true)
806{
807 global $rot_settings;
808 include_once "../includes/libs/distributions.php";
809 writelog("Calculate bayes ctr");
810 $q = "select total_points, total_shows, thumb_id from rot_gallery_stats" . $site_id . " where \r\n\ttotal_points > 0";
811 if ($new_only) {
812 $q .= " AND tested_thumb = 'no' ";
813 }
814 $q .= " AND thumb_id IN ('" . mt_implode("','", array_keys($thumb_ids), "", true) . "') ";
815 $q = db_query($q, $rot_settings["db_link"]);
816 if (db_num_rows($q) == 0) {
817 return NULL;
818 }
819 while ($d = db_fetch_assoc($q)) {
820 $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_ = $d["total_points"] / 1000;
821 $_obfuscated_0D17372A092D09232F1F0D250B220C3310163139143732_[$d["thumb_id"]] = 0 < $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_ && 0 < $d["total_shows"] - $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_ ? generate_random_beta_variate($_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_, $d["total_shows"] - $_obfuscated_0D151B1531301103123B0915330A121F370C2B1B1B3511_) : 0;
822 }
823 $q = "UPDATE IGNORE rot_gallery_stats" . $site_id . " SET total_ctr = CASE ";
824 foreach ($_obfuscated_0D17372A092D09232F1F0D250B220C3310163139143732_ as $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ => $_obfuscated_0D3D023431223C16033007061703081625283D253C3F32_) {
825 $q .= " WHEN thumb_id = '" . $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ . "' THEN '" . $_obfuscated_0D3D023431223C16033007061703081625283D253C3F32_ . "' ";
826 }
827 $q .= " END WHERE thumb_id IN ('" . mt_implode("','", array_keys($thumb_ids), "", true) . "') ";
828 db_query($q, $rot_settings["db_link"]);
829 writelog("Calculate bayes ctr :: Done");
830}
831function import_sets_process()
832{
833 global $rot_settings;
834 $q = "SELECT * FROM rot_import_sets WHERE ";
835 if ($_REQUEST["import_set"]) {
836 $q .= " set_id = " . (int) $_REQUEST["import_set"];
837 } else {
838 $q .= " status = 1 and period != 0 and next_grab < " . time();
839 }
840 $q = db_query($q);
841 while ($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_ = db_fetch_assoc($q)) {
842 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"] = unserialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]);
843 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["import_set_url"] = $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"];
844 writelog("ImportSet: process " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"]);
845 if (strstr($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"], "{PAGE}")) {
846 writelog("Looks like it's paginated import");
847 if (!$_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["page"]) {
848 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["page"] = 1;
849 } else {
850 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["page"]++;
851 }
852 db_query("UPDATE rot_import_sets SET options = '" . addslashes(serialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"])) . "' WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
853 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"] = str_replace("{PAGE}", $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["page"], $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"]);
854 writelog("Set url to " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"]);
855 }
856 if (!$_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"]) {
857 $tmp = DownloadFile($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"], "../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt");
858 @chmod("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt", 438);
859 if (!$tmp) {
860 write_script_warning("ImportSet : grabber error : can not get " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"] . " (" . $GLOBALS["last_error"] . ")", "grabber_errors");
861 continue;
862 }
863 $tmp = array();
864 if (10 * 1024 * 1024 < filesize("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt")) {
865 writelog("Importset mode: Largefile");
866 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"] = 1;
867 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["total_size"] = filesize("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt");
868 db_query("UPDATE rot_import_sets SET status = 1, options = '" . addslashes(serialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"])) . "', next_grab = 0 WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
869 } else {
870 if (file_exists("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt")) {
871 db_query("UPDATE rot_import_sets SET next_grab = " . (time() + $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["period"] * 3600) . " WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
872 $tmp["body"] = file_get_contents("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt");
873 }
874 }
875 } else {
876 $_obfuscated_0D130A3639100519400C2513232E0C18350F192D072B22_ = 500;
877 writelog("Large file :: adding " . $_obfuscated_0D130A3639100519400C2513232E0C18350F192D072B22_ . " lines (" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"] . " of " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["total_size"] . ") ");
878 if (!file_exists("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt")) {
879 writelog("Predownloaded file doesn't exist. Skip .. ");
880 unset($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"]);
881 unset($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["total_size"]);
882 db_query("UPDATE rot_import_sets SET status = 1, options = '" . addslashes(serialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"])) . "', next_grab = 0 WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
883 continue;
884 }
885 $_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_ = "../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt";
886 if (!($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_ = fopen($_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_, "r"))) {
887 writelog("Can not open " . $_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_ . " ");
888 continue;
889 }
890 if (1 < $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"]) {
891 if (fseek($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_, (int) $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"]) != 0) {
892 writelog("Can not read " . $_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_ . " ");
893 continue;
894 }
895 writelog("Read " . $_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_ . " from " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"] . " ");
896 }
897 $tmp["body"] = "";
898 $_obfuscated_0D5B06400B2D11013E2B0F0808240735340D0C3E0C0B11_ = 0;
899 while (!feof($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_)) {
900 $_obfuscated_0D5B06400B2D11013E2B0F0808240735340D0C3E0C0B11_++;
901 if ($_obfuscated_0D130A3639100519400C2513232E0C18350F192D072B22_ < $_obfuscated_0D5B06400B2D11013E2B0F0808240735340D0C3E0C0B11_) {
902 break;
903 }
904 $tmp["body"] .= fgets($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_, 1024 * 32);
905 }
906 $_obfuscated_0D39121038333E380530131735391C1E062417372A0A32_ = ftell($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_);
907 fclose($_obfuscated_0D2827010D0D032610113F2C3E190D1D193B0C1C321322_);
908 writelog("Large file :: Position " . $_obfuscated_0D39121038333E380530131735391C1E062417372A0A32_ . " , text size " . strlen($tmp["body"]));
909 if ($_obfuscated_0D39121038333E380530131735391C1E062417372A0A32_ == filesize($_obfuscated_0D2E152E2624102C28102A272A2C18382C35033D262722_)) {
910 writelog("Large file end.");
911 unlink("../tmp/import_set_" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . ".txt");
912 unset($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"]);
913 unset($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["total_size"]);
914 db_query("UPDATE rot_import_sets SET status = 0, options = '" . addslashes(serialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"])) . "', next_grab = 0 WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
915 } else {
916 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["large_file"] = $_obfuscated_0D39121038333E380530131735391C1E062417372A0A32_;
917 db_query("UPDATE rot_import_sets SET status = 1, options = '" . addslashes(serialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"])) . "', next_grab = 0 WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
918 }
919 }
920 if (stristr(substr($tmp["body"], 0, 50), "<rss") || stristr(substr($tmp["body"], 0, 50), "<?xml")) {
921 writelog("ImportSet: Looks like RSS");
922 if (!$_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["delimiter"]) {
923 $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["delimiter"] = "item";
924 }
925 $_obfuscated_0D172F5B1B083F261B2D2D2E16250C2A320532095B3B11_ = scj_parse_xml($tmp["body"], $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["delimiter"]);
926 if (!$_obfuscated_0D172F5B1B083F261B2D2D2E16250C2A320532095B3B11_) {
927 write_script_warning("ImportSet: can not parse " . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["url"] . " , please, contact support.", "grabber_errors");
928 if ($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]["page"]) {
929 writelog("Looks like the paginated set is over, pause importset");
930 db_query("UPDATE rot_import_sets SET status = 0 WHERE set_id = '" . $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["set_id"] . "' ");
931 }
932 } else {
933 $res = rotation_import($_obfuscated_0D172F5B1B083F261B2D2D2E16250C2A320532095B3B11_, unserialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["pattern"]), $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["delimiter"], $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]);
934 }
935 } else {
936 writelog("ImportSet: Looks like a regular dump");
937 $res = rotation_import($tmp["body"], unserialize($_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["pattern"]), $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["delimiter"], $_obfuscated_0D0C28102D333C3F16275B1F03371C061E2B1C13192332_["options"]);
938 }
939 writelog("ImportSet: Lines processed: " . $res["lines_processed"] . ", Added: " . $res["gallery_added"] . ", Dupes: " . $res["gallery_dupes"] . " Skip: " . array_count($res["gallery_filter_skipped"]));
940 }
941}
942function TS_import($group_d)
943{
944 global $rot_settings;
945 global $settings;
946 global $sponsors;
947 db_query("set wait_timeout=1200");
948 $group_id = $group_d["id"];
949 if (!$group_d["ts_works"]) {
950 return NULL;
951 }
952 db_query("update rot_groups set ts_last_update = '" . time() . "' where id = '" . $group_d["id"] . "' ");
953 writelog("TubeService: loading galls for " . $group_d["name"] . " (" . $group_id . ")");
954 $url = "http://smartcj.com/tg/bin/export.php?type=php_serialize&format=source_url|title|description|";
955 $url .= $group_d["ts_import_thumbs"] == "all" ? "all_thumbs" : "video_thumb";
956 $url .= "|embed_code|duration|keywords";
957 if ($group_d["ts_embed"]) {
958 $url .= "&embed_only=" . $group_d["ts_embed"];
959 }
960 if ($group_d["ts_keywords"]) {
961 $url .= "&keywords=" . urlencode($group_d["ts_keywords"]);
962 }
963 if ($group_d["ts_tubes"]) {
964 $url .= "&tubes=" . urlencode($group_d["ts_tubes"]);
965 }
966 $url .= "&start=" . (int) $_obfuscated_0D012D3523383135291210100A102E0F241D3F33231932_;
967 $url .= "&domain=" . urlencode($settings["site_url"]);
968 $url .= "&r=" . rand(1, 10000000);
969 writelog("Loading " . $url);
970 $tmp = get_url($url);
971 if ($tmp["status"] != 200) {
972 writelog("Error : " . $tmp["body"]);
973 } else {
974 $items = unserialize($tmp["body"]);
975 if (!is_array($items) || count($items) == 0) {
976 db_query("update rot_groups set ts_last_update = '" . time() . "' where id = '" . $group_d["id"] . "' ");
977 writelog("No items for this request");
978 } else {
979 $_obfuscated_0D262B153526183C322E011512111F2B1836221F1F3701_ = 0;
980 writelog(count($items) . " got for this req");
981 foreach ($items as $_obfuscated_0D3F4038241F311D261D0B331B02023215121209103532_ => $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_) {
982 if ($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["action"] == "delete") {
983 if (($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ = db_val("SELECT gallery_id FROM rot_gallery_info as gi\r\n\t\t\t\twhere gi.source_url = '" . addslashes($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"]) . "' ")) !== false) {
984 gallery_delete($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_, "mark_for_deletion");
985 }
986 continue;
987 }
988 if (db_value("url", "SELECT url FROM rot_gallery_info as gi\r\n\t\t\t\tJOIN rot_gallery_stats1 as gs on gs.gallery_id = gi.gallery_id\r\n\t\t\t\twhere gi.source_url = '" . addslashes($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"]) . "' and gs.group_id = '" . $group_id . "'")) {
989 writelog($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"] . " already exists in our DB ");
990 continue;
991 }
992 if (($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ = db_val("SELECT gallery_id FROM rot_gallery_info as gi\r\n\t\t\t\twhere gi.source_url = '" . addslashes($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"]) . "' ")) !== false) {
993 writelog($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"] . " exists, adding to group id " . $group_id . " ");
994 $groups = gallery_get_groups($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_);
995 $groups[] = $group_id;
996 gallery_set_groups($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_, $groups);
997 continue;
998 }
999 if ($group_d["ts_import_thumbs"] == "all") {
1000 $_obfuscated_0D0E3E1B5C3C3D2D222E1D30083D3E180D0C05102A0622_ = isset($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["all_thumbs"]) ? $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["all_thumbs"] : $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["video_thumb"];
1001 } else {
1002 $_obfuscated_0D0E3E1B5C3C3D2D222E1D30083D3E180D0C05102A0622_ = isset($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["video_thumb"]) ? array($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["video_thumb"]) : array($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["all_thumbs"][0]);
1003 }
1004 $_obfuscated_0D16261737101A1D3D3E340D243E211429180D08171022_ = 0;
1005 $_obfuscated_0D355C35061F1C05095C0A0C140707102C3F03235B1611_ = parse_url($_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"]);
1006 if (substr($_obfuscated_0D355C35061F1C05095C0A0C140707102C3F03235B1611_["host"], 0, 4) == "www.") {
1007 $_obfuscated_0D355C35061F1C05095C0A0C140707102C3F03235B1611_["host"] = substr($_obfuscated_0D355C35061F1C05095C0A0C140707102C3F03235B1611_["host"], 4);
1008 }
1009 foreach ($sponsors as $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_ => $_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_) {
1010 if ($_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_["sponsor_site"] == $_obfuscated_0D355C35061F1C05095C0A0C140707102C3F03235B1611_["host"]) {
1011 $_obfuscated_0D16261737101A1D3D3E340D243E211429180D08171022_ = $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_;
1012 break;
1013 }
1014 }
1015 $tmp = array();
1016 $tmp["url"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"];
1017 $tmp["source_url"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["source_url"];
1018 $tmp["groups"][] = $group_id;
1019 $tmp["thumbs"] = serialize($_obfuscated_0D0E3E1B5C3C3D2D222E1D30083D3E180D0C05102A0622_);
1020 $tmp["duration"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["duration"];
1021 $tmp["embed_code"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["embed_code"];
1022 $tmp["embed_template"] = "content_page";
1023 $tmp["crop_profile_id"] = $group_d["ts_crop_profile_id"];
1024 $tmp["sponsor_id"] = $_obfuscated_0D16261737101A1D3D3E340D243E211429180D08171022_ ? $_obfuscated_0D16261737101A1D3D3E340D243E211429180D08171022_ : $group_d["ts_sponsor_id"];
1025 $tmp["tags"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["keywords"];
1026 $tmp["linked_data"][1]["alt"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["title"];
1027 if ($rot_settings["ts_synonymize"]) {
1028 $tmp["linked_data"][1]["alt"] = synonymize_phrase($tmp["linked_data"][1]["alt"]);
1029 }
1030 $tmp["linked_data"][1]["description"] = $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["description"] ? $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["description"] : $_obfuscated_0D164039352D140B1707100F30222B190E2E3B0D162C01_["title"];
1031 if ($rot_settings["ts_synonymize"]) {
1032 $tmp["description"] = synonymize_phrase($tmp["description"]);
1033 }
1034 $tmp["date"] = time();
1035 $tmp["activation_date"] = date("Y-m-d H:i:s");
1036 if ($group_d["ts_status"] == "pool") {
1037 $_obfuscated_0D2B251A270237241C1D2E0914293C0D3C0C0140031922_ = "pool";
1038 } else {
1039 if ($group_d["ts_status"] == "active") {
1040 $_obfuscated_0D2B251A270237241C1D2E0914293C0D3C0C0140031922_ = "active";
1041 } else {
1042 $_obfuscated_0D2B251A270237241C1D2E0914293C0D3C0C0140031922_ = "preload";
1043 }
1044 }
1045 $tmp["grab_options"] = serialize(array("content_type_limit" => array("image", "movie", "flash"), "content_type_force" => 4, "thumb_count" => 100, "copy_thumbs" => "use_crop_profile", "copy_type" => "use_crop_profile", "grab_type" => $_obfuscated_0D2B251A270237241C1D2E0914293C0D3C0C0140031922_, "target_thumb_status" => $_obfuscated_0D2B251A270237241C1D2E0914293C0D3C0C0140031922_, "extra_crop_profile" => $group_d["ts_extra_crop_profile_id"] ? $group_d["ts_extra_crop_profile_id"] : 0));
1046 $_obfuscated_0D3412060C12393D361829080D250B0430341615224001_ = unserialize($tmp["grab_options"]);
1047 $tmp["status"] = 4;
1048 $r = AddGallery($tmp, $_obfuscated_0D3412060C12393D361829080D250B0430341615224001_);
1049 if ($r == "OK") {
1050 writelog($tmp["url"] . " added");
1051 } else {
1052 writelog($tmp["url"] . " was not added " . $r);
1053 }
1054 }
1055 }
1056 }
1057}
1058function check_db()
1059{
1060 global $rot_settings;
1061 global $config;
1062 if (($_REQUEST["check_db"] || rand(1, 100) == 1) && !$config["big_database_flag"]) {
1063 db_query("DELETE FROM rot_gallery_stats" . $rot_settings["linked_db_id"] . " WHERE thumb_id NOT IN (select thumb_id from rot_thumbs) ", $rot_settings["db_link"]);
1064 db_query("DELETE FROM rot_gal2tag where gallery_id NOT IN (select gallery_id from rot_gallery_info) ");
1065 db_query("DELETE FROM rot_gal2model where gallery_id NOT IN (select gallery_id from rot_gallery_info) ");
1066 if ($rot_settings["linked_db_id"] == 1 || $rot_settings["linked_db_id"] == $rot_settings["linked_description_id"]) {
1067 db_query("DELETE FROM rot_gallery_data" . $rot_settings["linked_description_id"] . " WHERE gallery_id NOT IN (select gallery_id from rot_gallery_info) ", $rot_settings["db_link"]);
1068 }
1069 }
1070}
1071function purge_cache()
1072{
1073 $_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_ = glob("../cache/*");
1074 if (count($_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_) == 0) {
1075 return NULL;
1076 }
1077 purge_cache_dir($_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_[rand(0, count($_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_) - 1)]);
1078}
1079function purge_cache_dir($dir)
1080{
1081 global $count;
1082 global $folders;
1083 $_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_ = glob($dir . "/*");
1084 $folders++;
1085 if ($folders % 10 == 0) {
1086 writelog("folders " . $folders);
1087 }
1088 foreach ($_obfuscated_0D08390E071C2A3435123B15022732141E2F1F2D332622_ as $z => $file) {
1089 if (is_dir($file)) {
1090 purge_cache_dir($file);
1091 } else {
1092 if (stristr($file, ".md")) {
1093 unlink($file);
1094 } else {
1095 $data = file_get_contents($file);
1096 if ($config["gzip_cache"]) {
1097 $data = gzuncompress($data);
1098 }
1099 $data = unserialize($data);
1100 if (time() < $data["expire"]) {
1101 unlink($file);
1102 if ($count % 10 == 0) {
1103 writelog("deleted " . $count);
1104 }
1105 }
1106 }
1107 }
1108 }
1109}
1110function delete_marked_thumbs()
1111{
1112 global $rot_settings;
1113 global $cache;
1114 writelog("Delete thumbs marked for deletion");
1115 for ($_obfuscated_0D18261D5C010F3C082D04390C0B1D0D30261B231B3501_ = 0; true; $_obfuscated_0D18261D5C010F3C082D04390C0B1D0D30261B231B3501_++) {
1116 if (!$_REQUEST["process_deleted"] && 1000 < $_obfuscated_0D18261D5C010F3C082D04390C0B1D0D30261B231B3501_) {
1117 break;
1118 }
1119 $d = db_get_row("SELECT gallery_id FROM rot_gallery_info WHERE gallery_status = 'to_delete' LIMIT 0, 1");
1120 if (!$d) {
1121 break;
1122 }
1123 writelog("Deleting gallery_id " . $d["gallery_id"]);
1124 gallery_delete($d["gallery_id"]);
1125 Cache::delete("item_" . $d["gallery_id"]);
1126 if ($_obfuscated_0D18261D5C010F3C082D04390C0B1D0D30261B231B3501_ % 10 == 0) {
1127 writelog("Deleted " . $_obfuscated_0D18261D5C010F3C082D04390C0B1D0D30261B231B3501_ . " ");
1128 }
1129 }
1130 return true;
1131}
1132function reset_models()
1133{
1134 global $rot_settings;
1135 set_time_limit(0);
1136 writelog("Reset models :: started");
1137 $res = array();
1138 $q = db_query("SELECT model_id, model_name FROM rot_models");
1139 $_obfuscated_0D3734051B055B0B221B402C123C3821143D2701270511_ = db_num_rows($q);
1140 while ($d = db_fetch_assoc($q)) {
1141 if (!strstr(trim($d["model_name"]), " ")) {
1142 continue;
1143 }
1144 $count++;
1145 writelog("Checking model " . $d["model_name"] . " (" . $count . " of " . $_obfuscated_0D3734051B055B0B221B402C123C3821143D2701270511_ . ")");
1146 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_["search"] = "\"" . $d["model_name"] . "\"";
1147 $_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_ = rot_get_items_prepare_query($_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_, 0, 10000, $rot_settings, false);
1148 $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_ = rot_get_item_execute_query($_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_, $_obfuscated_0D19043F1738123F08363E292D1D363909121334350922_, $rot_settings);
1149 if ($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["total"] == 0 || count($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["items"]) == 0) {
1150 continue;
1151 }
1152 writelog("Galleries with this model " . $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["total"]);
1153 $_obfuscated_0D17072A06195B401D26081C341B18230D3137342F3601_ = "INSERT IGNORE INTO rot_gal2model (model_id, gallery_id) values ";
1154 foreach ($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["items"] as $z => $_obfuscated_0D255C361C183C08011E192B0C043C380F1D2A02380B32_) {
1155 $_obfuscated_0D17072A06195B401D26081C341B18230D3137342F3601_ .= "(" . $d["model_id"] . ", " . $_obfuscated_0D255C361C183C08011E192B0C043C380F1D2A02380B32_["gallery_id"] . "), ";
1156 }
1157 $_obfuscated_0D17072A06195B401D26081C341B18230D3137342F3601_ = substr($_obfuscated_0D17072A06195B401D26081C341B18230D3137342F3601_, 0, -2);
1158 db_query($_obfuscated_0D17072A06195B401D26081C341B18230D3137342F3601_);
1159 }
1160}
1161function reset_thumb_cats()
1162{
1163 set_time_limit(0);
1164 writelog("reset_thumb_cats: reassign galleries to categories");
1165 $q = db_query("select id, name, ts_keywords from rot_groups");
1166 while ($d = db_fetch_assoc($q)) {
1167 $_obfuscated_0D18173927353E2C0B32261D053725152C2734155B3032_[strtolower($d["name"])] = $d["id"];
1168 $_obfuscated_0D3C320D2D10021C241E051D3E043332360917320B3232_[$d["id"]] = $d["ts_keywords"];
1169 }
1170 $q = db_query("SELECT gi.gallery_id, alt, description, duration, activation_date,\r\n\t(SELECT group_concat(tag_name) FROM rot_gal2tag g2t \r\n\tLEFT JOIN rot_tags as t on t.tag_id = g2t.tag_id \r\n\tWHERE g2t.gallery_id = gi.gallery_id) as tags\r\n\r\n\tFROM rot_gallery_info as gi\r\n\tLEFT JOIN rot_gallery_data1 as gd ON gd.gallery_id = gi.gallery_id\r\n\r\n\tWHERE gi.gallery_type = 0");
1171 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1172 $count = 0;
1173 while ($d = db_fetch_assoc($q)) {
1174 $count++;
1175 if ($count % 100 == 0) {
1176 writelog("reset_thumb_cats:: " . $count . " of " . $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_);
1177 }
1178 $d["groups"] = $_obfuscated_0D2C4001021E2C15162D3E0B313B40283E0C1E3B332932_ = detect_categories(" " . $d["tags"] . " " . $d["alt"] . " " . $d["description"] . " ", $_obfuscated_0D3C320D2D10021C241E051D3E043332360917320B3232_);
1179 if (count($_obfuscated_0D2C4001021E2C15162D3E0B313B40283E0C1E3B332932_)) {
1180 $_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_ = db_query("SELECT thumb_id FROM rot_thumbs WHERE gallery_id = '" . $d["gallery_id"] . "' ");
1181 while ($d1 = db_fetch_assoc($_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_)) {
1182 gallery_add_stats_record($d1["thumb_id"], $d);
1183 }
1184 }
1185 }
1186 writelog("ReSet Categories - Done");
1187}
1188function update_cell_ctr($page_ids = array())
1189{
1190 $q = "SELECT max(clicks) as total_clicks, page_id\tFROM `rot_cell_data`";
1191 if (count($page_ids)) {
1192 $q .= " WHERE page_id IN ('" . mt_implode("','", $page_ids) . "')";
1193 }
1194 $q .= "\tGROUP BY page_id HAVING total_clicks > 100 ";
1195 $q = db_query($q);
1196 while ($d = db_fetch_assoc($q)) {
1197 $res = array();
1198 $_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_ = db_query("SELECT show_place, clicks FROM `rot_cell_data` where page_id = '" . $d["page_id"] . "'");
1199 while ($d1 = db_fetch_assoc($_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_)) {
1200 $res[$d1["show_place"]] = sqrt(sqrt($d1["clicks"] / $d["total_clicks"]));
1201 }
1202 if ($res) {
1203 $_obfuscated_0D140C0B34191C3113172811050915183538103B100A22_ = "UPDATE LOW_PRIORITY rot_cell_data set cell_ctr = CASE";
1204 foreach ($res as $_obfuscated_0D252211303F0C030B21330F301A301E2E263E38071322_ => $_obfuscated_0D3D023431223C16033007061703081625283D253C3F32_) {
1205 $_obfuscated_0D140C0B34191C3113172811050915183538103B100A22_ .= " WHEN show_place = " . $_obfuscated_0D252211303F0C030B21330F301A301E2E263E38071322_ . " THEN '" . $_obfuscated_0D3D023431223C16033007061703081625283D253C3F32_ . "' ";
1206 }
1207 $_obfuscated_0D140C0B34191C3113172811050915183538103B100A22_ .= " END WHERE page_id = '" . $d["page_id"] . "' ";
1208 db_query($_obfuscated_0D140C0B34191C3113172811050915183538103B100A22_);
1209 }
1210 }
1211}
1212function get_rot_page_items($all_pages = array())
1213{
1214 global $rot_settings;
1215 $rot_settings["page_items_file"] = true;
1216 if ($rot_settings["page_items_file"]) {
1217 foreach ($all_pages as $z => $_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_) {
1218 if (!$_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_) {
1219 continue;
1220 }
1221 if (!($d = Cache::get($_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_))) {
1222 continue;
1223 }
1224 $items[$_obfuscated_0D0324402C372E2132220A0F1227390F1A15150A210A01_] = $d;
1225 }
1226 } else {
1227 $items = array();
1228 $q = db_query("select page_crc, items from rot_page_items\r\n\t where page_crc IN ('" . mt_implode("','", $all_pages, "", true) . "')");
1229 while ($d = db_fetch_assoc($q)) {
1230 $d["items"] = explode("|", $d["items"]);
1231 $items[$d["page_crc"]] = $d["items"];
1232 }
1233 }
1234 return $items;
1235}
1236function synomize_all_descriptions()
1237{
1238 global $rot_settings;
1239 global $verbose;
1240 db_query("update rot_settings set value = '' where name = 'force_rotation'");
1241 $verbose = 3;
1242 set_time_limit(0);
1243 if ($rot_settings["linked_db_id"]) {
1244 $rot_settings["ts_synonymize_percent"] = db_value("synomyze", "SELECT synomyze FROM rot_linked_db WHERE rot_linked_id = '" . $rot_settings["linked_db_id"] . "' ", $rot_settings["db_link"]);
1245 $rot_settings["synonymize_method"] = db_value("value", "SELECT value FROM rot_settings WHERE name = 'synonymize_method' ", $rot_settings["db_link"]);
1246 }
1247 writelog("synomize_all_description: start (percent " . $rot_settings["ts_synonymize_percent"] . " method: " . $rot_settings["synonymize_method"] . " )");
1248 if (!$rot_settings["ts_synonymize_percent"]) {
1249 writelog("Synomize is off in rotation setting of this site");
1250 } else {
1251 if ($rot_settings["linked_db_id"] && !$rot_settings["linked_description_id"]) {
1252 writelog("This site doesnt have separate descriptions");
1253 } else {
1254 $q = db_query("SELECT gi.gallery_id, alt, description, gallery_slug FROM rot_gallery_data" . $rot_settings["linked_description_id"] . " as gd\r\n\tLEFT JOIN rot_gallery_info as gi on gi.gallery_id = gd.gallery_id\r\n\tWHERE gi.gallery_type = 0", $rot_settings["db_link"]);
1255 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1256 while ($d = db_fetch_assoc($q)) {
1257 $_obfuscated_0D0B225C353C1E02213B390E5C341B0F0308050C382122_ = synonymize_phrase($d["alt"], $rot_settings["ts_synonymize_percent"]);
1258 $_obfuscated_0D2F37282A1422110102364014152E1F12391D21261922_ = synonymize_phrase($d["description"], $rot_settings["ts_synonymize_percent"]);
1259 if ($_obfuscated_0D0B225C353C1E02213B390E5C341B0F0308050C382122_ != $d["alt"] || $_obfuscated_0D2F37282A1422110102364014152E1F12391D21261922_ != $d["description"] || $d["linked_data"][$rot_settings["linked_description_id"]]["gallery_slug"] == "") {
1260 $d["linked_data"][$rot_settings["linked_description_id"]]["alt"] = $_obfuscated_0D0B225C353C1E02213B390E5C341B0F0308050C382122_;
1261 $d["linked_data"][$rot_settings["linked_description_id"]]["description"] = $_obfuscated_0D2F37282A1422110102364014152E1F12391D21261922_;
1262 if (!$d["linked_data"][$rot_settings["linked_description_id"]]["gallery_slug"]) {
1263 $d["linked_data"][$rot_settings["linked_description_id"]]["gallery_slug"] = $d["gallery_slug"];
1264 }
1265 $d["linked_data"][$rot_settings["linked_description_id"]]["gallery_slug"] = gallery_create_slug($d, $rot_settings["linked_description_id"]);
1266 db_query("UPDATE rot_gallery_data" . $rot_settings["linked_description_id"] . " SET alt = '" . addslashes($d["linked_data"][$rot_settings["linked_description_id"]]["alt"]) . "', \r\n\t\t\tdescription = '" . addslashes($d["linked_data"][$rot_settings["linked_description_id"]]["description"]) . "' ,\r\n\t\t\tgallery_slug = '" . addslashes($d["linked_data"][$rot_settings["linked_description_id"]]["gallery_slug"]) . "' \r\n\t\t\tWHERE gallery_id = '" . $d["gallery_id"] . "' ", $rot_settings["db_link"]);
1267 add_tags($d["gallery_id"], $_obfuscated_0D0B225C353C1E02213B390E5C341B0F0308050C382122_ . " " . $_obfuscated_0D2F37282A1422110102364014152E1F12391D21261922_, array(), $rot_settings["linked_db_id"]);
1268 }
1269 $count++;
1270 if ($count % 100 == 0) {
1271 echo "Synomized " . $count . " of " . $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ . " \n";
1272 }
1273 }
1274 writelog("Synomizing is Done");
1275 }
1276 }
1277}
1278function reassign_tags($set)
1279{
1280 global $rot_settings;
1281 writelog("Reassign tags");
1282 db_query("update rot_settings set value = '' where name = 'force_rotation'");
1283 $_obfuscated_0D040B2D011A082D281F24290229083B15221722341911_ = array();
1284 if ($set["tag_source"] == "white_black_list") {
1285 $_obfuscated_0D150123401E3D1E092C0E1D395B232A0B3E1822210101_ = explode_clean("\n", $rot_settings["tags_whitelist"]);
1286 if (count($_obfuscated_0D150123401E3D1E092C0E1D395B232A0B3E1822210101_) < 2) {
1287 writelog("White list is empty");
1288 return NULL;
1289 }
1290 foreach ($_obfuscated_0D150123401E3D1E092C0E1D395B232A0B3E1822210101_ as $z => $tmp) {
1291 $tmp = preg_split("|[,\\|]|", $tmp);
1292 foreach ($tmp as $z => $_obfuscated_0D2615172C3B02221A3E24321006121B0F400C0C123511_) {
1293 $tmp[$z] = strtolower(trim($_obfuscated_0D2615172C3B02221A3E24321006121B0F400C0C123511_));
1294 }
1295 $GLOBALS["tags_white_list"][] = array_flip($tmp);
1296 }
1297 if (count($GLOBALS["tags_white_list"]) < 2) {
1298 writelog("White list is empty ? aborting");
1299 return NULL;
1300 }
1301 unset($_obfuscated_0D150123401E3D1E092C0E1D395B232A0B3E1822210101_);
1302 }
1303 if ($set["tag_source"] == "autocreate") {
1304 $_obfuscated_0D040B2D011A082D281F24290229083B15221722341911_["skip_whitelist"] = true;
1305 }
1306 $q = "SELECT gd.gallery_id, alt, description, custom_var1, custom_var2, custom_var3 from rot_gallery_data" . $rot_settings["linked_db_id"] . " as gd \r\n\tLEFT JOIN rot_gallery_info as gi ON gi.gallery_id = gd.gallery_id \r\n\tWHERE gallery_type = 0 ";
1307 $q .= $set["target_galleries"] == "all_galleries" ? "" : " and gd.gallery_id NOT IN (SELECT gallery_id FROM rot_gal2tag) ";
1308 $q = db_query($q);
1309 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1310 writelog((string) $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ . " to assign");
1311 while ($d = db_fetch_assoc($q)) {
1312 $str = "";
1313 if ($set["tag_fields"]["alt"]) {
1314 $str .= " " . $d["alt"] . " ";
1315 }
1316 if ($set["tag_fields"]["description"]) {
1317 $str .= " " . $d["description"] . " ";
1318 }
1319 if ($set["tag_fields"]["custom_vars"]) {
1320 $str .= " " . $d["custom_var1"] . " " . $d["custom_var2"] . " " . $d["custom_var3"] . " ";
1321 }
1322 $_obfuscated_0D372C1E1538113D272218120F181C3D23090E2A032932_ = add_tags($d["gallery_id"], str_replace("|", " ", $str), $_obfuscated_0D040B2D011A082D281F24290229083B15221722341911_);
1323 $count++;
1324 if ($count % 100 == 0) {
1325 writelog((string) $count . " of " . $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_);
1326 }
1327 }
1328}
1329function cat0_thumb_shift($value)
1330{
1331 if (!$value) {
1332 $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ = 0;
1333 } else {
1334 if ($value == "rand3") {
1335 $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ = rand(0, 2);
1336 } else {
1337 if ($value == "rand5") {
1338 $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ = rand(0, 4);
1339 } else {
1340 if ($value == "rand10") {
1341 $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ = rand(0, 9);
1342 } else {
1343 $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ = $value;
1344 }
1345 }
1346 }
1347 }
1348 writelog("Cat shift " . $_obfuscated_0D181030391506281527342321051E0A265B4033210332_ . " ");
1349 return $_obfuscated_0D181030391506281527342321051E0A265B4033210332_;
1350}
1351function cat0_categories($task)
1352{
1353 global $rot_settings;
1354 global $sponsors;
1355 global $config;
1356 writelog("Updating Cat0 (" . print_r($task, true) . ") ");
1357 foreach (rot_get_sponsors() as $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_ => $_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_) {
1358 if (!$_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_["status"]) {
1359 $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_[] = $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_;
1360 }
1361 }
1362 $_obfuscated_0D09182B321011123C3F395C2523140D283E1A2C0D1722_ = $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_ = array(1);
1363 $_obfuscated_0D042F052C36323D1D391A3723221A0A06112613140E22_ = array();
1364 if ($rot_settings["slave_unique_cat_thumbs"]) {
1365 $q = db_query("SELECT category_thumb_ids FROM rot_linked_db WHERE rot_linked_id != '" . (int) $rot_settings["linked_db_id"] . "' ", $rot_settings["db_link"]);
1366 while ($d = db_fetch_assoc($q)) {
1367 $tmp = unserialize($d["category_thumb_ids"]);
1368 if (is_array($tmp)) {
1369 $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_ = array_merge($_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_, $tmp);
1370 }
1371 }
1372 }
1373 $_obfuscated_0D2C3F36235B02082C1B361715235C213C2B3E1E030B22_ = $task["site_stat_id"] ? $task["site_stat_id"] : $rot_settings["linked_db_id"];
1374 $_obfuscated_0D28240B090C090E3835250907032913100125373D2E32_ = load_categories("ctr", 0, $_obfuscated_0D2C3F36235B02082C1B361715235C213C2B3E1E030B22_, $_obfuscated_0D2C3F36235B02082C1B361715235C213C2B3E1E030B22_);
1375 $q = "SELECT group_id, count(distinct(gs.gallery_id)) as total FROM rot_gallery_stats1 as gs \r\n\t\t\tJOIN rot_gallery_info as gi on gi.gallery_id = gs.gallery_id\r\n\t\t\tWHERE gi.gallery_status = 'active' AND gi.gallery_type = 0 and gs.best_thumb = 'yes' ";
1376 if (is_array($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) && count($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_)) {
1377 $q .= " AND gi.sponsor_id NOT IN (" . join(",", $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) . ") ";
1378 }
1379 if (is_array($task["skip_group_ids"]) && count($task["skip_group_ids"])) {
1380 if ($rot_settings["group_exclusion"] == "soft") {
1381 $q .= " and gs.group_id NOT IN ('" . mt_implode("','", $task["skip_group_ids"], "", true) . "') ";
1382 } else {
1383 $q .= " and gs.gallery_id NOT IN ( SELECT gallery_id FROM rot_gallery_stats1 WHERE group_id IN ('" . mt_implode("','", $task["skip_group_ids"], "", true) . "')) ";
1384 }
1385 }
1386 if ($task["content_type"]) {
1387 $q .= " AND content_type = '" . addslashes($task["content_type"]) . "' ";
1388 }
1389 $q .= "\tgroup by group_id ";
1390 $q = db_query($q, $rot_settings["db_link"]);
1391 $_obfuscated_0D3F3F0F10361B3232293B0E301E2D30102D3502063011_ = array();
1392 while ($d = db_fetch_assoc($q)) {
1393 $_obfuscated_0D3F3F0F10361B3232293B0E301E2D30102D3502063011_[$d["group_id"]] = $d["total"];
1394 }
1395 foreach ($_obfuscated_0D28240B090C090E3835250907032913100125373D2E32_ as $z => $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_) {
1396 if (is_array($task["skip_group_ids"]) && in_array($_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"], $task["skip_group_ids"])) {
1397 continue;
1398 }
1399 writelog("Select best cat thumbs for " . $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["category_name"] . " (id: " . $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"] . "), set " . $task["set_id"] . " shift " . $task["thumb_shift"] . " ");
1400 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_ = array("group_id" => $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"], "site_id" => $task["site_stat_id"], "tested_first" => true);
1401 if (is_array($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) && count($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_)) {
1402 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_["skip_sponsors"] = $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_;
1403 }
1404 if (is_array($task["skip_group_ids"]) && count($task["skip_group_ids"])) {
1405 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_["inactive_groups"] = $task["skip_group_ids"];
1406 }
1407 if ($task["content_type"]) {
1408 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_["content_type"] = $task["content_type"];
1409 }
1410 if ($task["thumb_shift"] === "date_last") {
1411 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_["order"] = "date";
1412 }
1413 $_obfuscated_0D2F15061E0B1F25401D0139192418290F243C340B0D22_ = $task["thumb_shift"] + count($_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_) + 1;
1414 if ($_obfuscated_0D2F15061E0B1F25401D0139192418290F243C340B0D22_ < 20) {
1415 $_obfuscated_0D2F15061E0B1F25401D0139192418290F243C340B0D22_ = 20;
1416 }
1417 $_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_ = rot_get_items_prepare_query($_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_, 0, $_obfuscated_0D2F15061E0B1F25401D0139192418290F243C340B0D22_, $rot_settings, false);
1418 $_obfuscated_0D132126361D315B051822300F5B2C111036190A331622_ = 0;
1419 $_obfuscated_0D3C21321F0F13051212343516101C3D162F2E2E5C2C22_ = $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_ = array();
1420 $_obfuscated_0D112A395B153E113E10402C320E33072A033F3F311A01_ = array();
1421 $_obfuscated_0D1835173B0F062B060C2E3C05330510233E0326342322_ = false;
1422 $q = db_query($_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_, $rot_settings["db_link"]);
1423 while ($_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_ = db_fetch_assoc($q)) {
1424 $_obfuscated_0D132126361D315B051822300F5B2C111036190A331622_++;
1425 $_obfuscated_0D112A395B153E113E10402C320E33072A033F3F311A01_[] = $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["thumb_id"];
1426 if ($_obfuscated_0D1835173B0F062B060C2E3C05330510233E0326342322_) {
1427 continue;
1428 }
1429 if ($_obfuscated_0D132126361D315B051822300F5B2C111036190A331622_ == 1) {
1430 $_obfuscated_0D3C21321F0F13051212343516101C3D162F2E2E5C2C22_ = $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_;
1431 }
1432 if ($_obfuscated_0D132126361D315B051822300F5B2C111036190A331622_ < $task["thumb_shift"]) {
1433 continue;
1434 }
1435 if (in_array($_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["thumb_id"], $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_)) {
1436 continue;
1437 }
1438 $_obfuscated_0D1835173B0F062B060C2E3C05330510233E0326342322_ = $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_;
1439 }
1440 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_ = $_obfuscated_0D1835173B0F062B060C2E3C05330510233E0326342322_;
1441 if (!$_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_) {
1442 if ($_obfuscated_0D3C21321F0F13051212343516101C3D162F2E2E5C2C22_) {
1443 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_ = $_obfuscated_0D3C21321F0F13051212343516101C3D162F2E2E5C2C22_;
1444 } else {
1445 writelog("No thumbs in this category at all");
1446 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["source_url"] = !$task["site_id"] ? $rot_settings["linked_db_id"] : $task["site_id"];
1447 db_query("UPDATE rot_gallery_info SET content_count = '0' \r\n \t\t\tWHERE gallery_type = 1\r\n\t\t \tAND content_type = '" . addslashes($task["set_id"]) . "'\r\n\t\t\t AND url = '" . $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"] . "' \r\n\t\t\t AND source_url = '" . $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["source_url"] . "' ", $rot_settings["db_link"]);
1448 continue;
1449 }
1450 }
1451 $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_[] = (int) $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["thumb_id"];
1452 $_obfuscated_0D09182B321011123C3F395C2523140D283E1A2C0D1722_[] = (int) $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["thumb_id"];
1453 writelog("Selected thumb id " . $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["thumb_id"] . " for " . $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["category_name"] . ", total items in group: " . $_obfuscated_0D3F3F0F10361B3232293B0E301E2D30102D3502063011_[$_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"]] . " ");
1454 foreach (linked_sites() as $_obfuscated_0D365B292804021E33270C1D331E3F10023834010F3822_ => $_obfuscated_0D280E5B1A2E032E121339252C2D1E01181A07292B1732_) {
1455 if (!$_obfuscated_0D280E5B1A2E032E121339252C2D1E01181A07292B1732_["separate_vars"]) {
1456 continue;
1457 }
1458 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["linked_data"][$_obfuscated_0D365B292804021E33270C1D331E3F10023834010F3822_] = db_get_row("SELECT * FROM rot_gallery_data" . $_obfuscated_0D365B292804021E33270C1D331E3F10023834010F3822_ . " WHERE gallery_id = " . $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["gallery_id"] . " LIMIT 1 ", $rot_settings["db_link"]);
1459 unset($_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["linked_data"][$_obfuscated_0D365B292804021E33270C1D331E3F10023834010F3822_]["gallery_id"]);
1460 unset($_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["linked_data"][$_obfuscated_0D365B292804021E33270C1D331E3F10023834010F3822_]["gallery_slug"]);
1461 }
1462 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["content_count"] = $_obfuscated_0D3F3F0F10361B3232293B0E301E2D30102D3502063011_[$_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"]];
1463 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["url"] = $_obfuscated_0D0540225B030F3F3F2F25401725373504402240365C01_["group_id"];
1464 $_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_["linked_data"][$task["site_id"]]["custom_var2"] = join(",", array_slice($_obfuscated_0D112A395B153E113E10402C320E33072A033F3F311A01_, 0, 20));
1465 insert_cat0($_obfuscated_0D22162A5B1C3403271F18230C2A2B0A031C03350E2B11_, "cat0", $task["set_id"], $task["site_id"]);
1466 }
1467 db_query("UPDATE rot_linked_db SET category_thumb_ids = '" . addslashes(serialize($_obfuscated_0D09182B321011123C3F395C2523140D283E1A2C0D1722_)) . "' WHERE rot_linked_id = '" . (int) $_obfuscated_0D2C3F36235B02082C1B361715235C213C2B3E1E030B22_ . "' ", $rot_settings["db_link"]);
1468 return true;
1469}
1470function insert_cat0($best_item, $item_type = "cat0", $set_id = 0, $site_id = false)
1471{
1472 global $rot_settings;
1473 $_obfuscated_0D3035020E1517071B35361F060A2A34305B2307320922_ = array("cat0" => 1, "model" => 2, "tag" => 3);
1474 if ($best_item["thumb_id"]) {
1475 $_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_ = db_get_row("SELECT * FROM rot_thumbs WHERE thumb_id = '" . (int) $best_item["thumb_id"] . "' ", $rot_settings["db_link"]);
1476 } else {
1477 $_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_ = db_get_row("SELECT * FROM rot_thumbs WHERE gallery_id = '" . (int) $best_item["gallery_id"] . "' AND thumb_url = '" . addslashes($best_item["thumb_url"]) . "' ", $rot_settings["db_link"]);
1478 }
1479 unset($best_item["gallery_id"]);
1480 $best_item["gallery_type"] = $_obfuscated_0D3035020E1517071B35361F060A2A34305B2307320922_[$item_type];
1481 $best_item["sponsor_id"] = $best_item["thumb_id"];
1482 $best_item["source_url"] = !$site_id ? $rot_settings["linked_db_id"] : $site_id;
1483 $best_item["activation_date"] = date("Y-m-d H:i:s", time());
1484 $best_item["content_type"] = $set_id;
1485 $best_item["gallery_status"] = "active";
1486 $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ = db_val("SELECT gi.gallery_id FROM rot_gallery_info as gi\r\n JOIN rot_thumbs as rt ON rt.gallery_id = gi.gallery_id\r\n WHERE gi.gallery_type = '" . $best_item["gallery_type"] . "' \r\n AND content_type = '" . $set_id . "' \r\n AND url = '" . $best_item["url"] . "' \r\n AND source_url = '" . $best_item["source_url"] . "' ", $rot_settings["db_link"]);
1487 if (!$_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_) {
1488 unset($best_item["gallery_id"]);
1489 $best_item["gallery_id"] = $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ = gallery_add($best_item);
1490 db_perform("rot_thumbs", array("gallery_id" => $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_, "thumb_url" => $best_item["thumb_url"], "height" => $_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_["height"], "width" => $_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_["width"]), "insert", "", $rot_settings["db_link"]);
1491 $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ = db_insert_id($rot_settings["db_link"]);
1492 gallery_add_stats_record($_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_, $best_item);
1493 gallery_select_best_thumb($_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_);
1494 } else {
1495 $best_item["gallery_id"] = $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_;
1496 unset($_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_["thumb_id"]);
1497 unset($_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_["gallery_id"]);
1498 db_perform("rot_thumbs", $_obfuscated_0D08300B3527083F0323180E171C325C13341C2C140801_, "update", " gallery_id = '" . $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ . "' ", $rot_settings["db_link"]);
1499 db_query("UPDATE rot_gallery_info SET content_count = '" . (int) $best_item["content_count"] . "', crop_profile_id = '" . (int) $best_item["crop_profile_id"] . "',\r\n \tsponsor_id = '" . (int) $best_item["sponsor_id"] . "' WHERE gallery_id = '" . $_obfuscated_0D5B2D3C1A3B0F0A5C051A3F40312A0B112C352B363C11_ . "' ", $rot_settings["db_link"]);
1500 }
1501 gallery_update_data_vars($best_item);
1502}
1503function cat0_process($task = array())
1504{
1505 global $rot_settings;
1506 global $sponsors;
1507 global $config;
1508 global $cache;
1509 foreach ((array) $sponsors as $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_ => $_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_) {
1510 if (!$_obfuscated_0D172613061839280F1B3C3C242315160B26370A403822_["status"]) {
1511 $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_[] = $_obfuscated_0D1A131306223807262A0D273717330932373E3D130801_;
1512 }
1513 }
1514 if ($task["cat0_type"] == "cat0") {
1515 $query = "select group_id as id, name, GROUP_CONCAT(thumb_id order by new_thumb ASC, total_ctr DESC) as thumbs_list from ( \r\n\t\tSELECT gs.thumb_id, g.gallery_md5, gr.name, g2gr.group_id, gs.total_ctr, if (gs.total_shows < " . (int) $rot_settings["new_thumbs_shows"] . ", 1, 0) as new_thumb FROM rot_galleries as g\r\n\t\tLEFT JOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs ON gs.thumb_id = g.id\r\n\t\tLEFT JOIN rot_gal2group as g2gr ON g2gr.gal_id = g.id\r\n\t\tLEFT JOIN rot_groups as gr on gr.id = g2gr.group_id\r\n\t\tWHERE gs.best_thumb = 'yes' and g.rgroup != 0 and status = 1 ";
1516 if (count($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_)) {
1517 $query .= " and g.sponsor_id NOT IN (" . join(",", $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) . ") ";
1518 }
1519 if ($task["content_type"]) {
1520 $query .= " and g.content_type = '" . (int) $task["content_type"] . "' ";
1521 }
1522 if ($task["thumb_shift"] != "date_last") {
1523 $query .= " ORDER BY gr.id, gs.total_ctr DESC ) as top_galleries group by group_id ";
1524 }
1525 cat0_select($task["cat0_type"], $query, false, $task["set_id"], $task["thumb_shift"], $task["content_type"]);
1526 }
1527 if ($task["cat0_type"] == "model") {
1528 $query = "select model_id as id, name, GROUP_CONCAT(thumb_id ORDER BY total_ctr DESC) as thumbs_list from ( \r\n\t\t\tSELECT gs.thumb_id, g2m.model_id, m.model_name as name, gs.total_ctr FROM rot_gallery_info as gi\r\n\t\t\tLEFT JOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs ON gs.gallery_id = gi.gallery_id\r\n\t\t\tLEFT JOIN rot_gal2model as g2m ON gi.gallery_id = g2m.gallery_id\r\n\t\t\tLEFT JOIN rot_models as m ON m.model_id = g2m.model_id\r\n\t\t\tWHERE gs.best_thumb = 'yes' and gs.group_id = 0 and gs.best_thumb = 'yes' and\r\n\t\t\tgallery_status = 'active' and g2m.model_id IS NOT NULL \r\n\t\t\tand gi.gallery_type = 0\r\n\t\t\tAND m.model_name IS NOT NULL ";
1529 if (array_count($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_)) {
1530 $query .= " and gi.sponsor_id NOT IN (" . join(",", $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) . ") ";
1531 }
1532 if ($task["content_type"]) {
1533 $query .= " and gi.content_type = '" . (int) $task["content_type"] . "' ";
1534 }
1535 $query .= " ORDER BY g2m.model_id, gs.total_ctr desc \r\n\t\t\t) as top_galleries \r\n\t\t\tgroup by model_id ";
1536 cat0_select($task["cat0_type"], $query, false, $task["set_id"], $task["thumb_shift"], $task["content_type"]);
1537 }
1538 if ($task["cat0_type"] == "tag") {
1539 $query = "select tag_id as id, tag_name as name, ( \r\n\r\n\t\tSELECT group_concat(DISTINCT(gs.thumb_id) order by tested_thumb DESC, gs.total_ctr DESC) FROM rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs\r\n\t\tLEFT JOIN rot_gallery_info as gi ON gi.gallery_id = gs.gallery_id\r\n\t\tLEFT JOIN rot_gal2tag as g2t ON gi.gallery_id = g2t.gallery_id \r\n\t\tWHERE gs.best_thumb = 'yes' and gi.gallery_type = 0 and gi.gallery_status = 'active' and gs.best_thumb = 'yes'\r\n\t\tand t.status = 'active' and g2t.tag_id IS NOT NULL ";
1540 if (array_count($_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_)) {
1541 $query .= " and gi.sponsor_id NOT IN (" . join(",", $_obfuscated_0D060921091F15395B0B142C2D362F152835062F403B22_) . ") ";
1542 }
1543 if ($task["content_type"]) {
1544 $query .= " and gi.content_type = '" . (int) $task["content_type"] . "' ";
1545 }
1546 $query .= " and t.tag_id = g2t.tag_id\r\n\t\tORDER BY gs.total_ctr desc \r\n\t\t) as thumbs_list \r\n\r\n\t\tfrom rot_tags as t WHERE t.status = 'active'";
1547 cat0_select($task["cat0_type"], $query, isset($rot_settings["select_tag_best_thumb_unique_only"]) && $rot_settings["select_tag_best_thumb_unique_only"] ? false : true, $task["set_id"], $task["thumb_shift"], $task["content_type"]);
1548 }
1549}
1550function cat0_select($type, $query, $allow_dupes = true, $set_id = 0, $thumb_shift = 0, $content_type = 0)
1551{
1552 global $rot_settings;
1553 global $sponsors;
1554 global $config;
1555 global $cache;
1556 $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_ = array();
1557 if ($type == "cat0") {
1558 $_obfuscated_0D293F2D3B012A0107221A070818340238232517290E22_ = $rot_settings["linked_db_id"] ? " and source_url = '" . $rot_settings["linked_db_id"] . "' " : " and source_url = '' ";
1559 $_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_ = array();
1560 $q = db_query("SELECT url FROM rot_galleries as g\r\n\t\tLEFT JOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs ON gs.thumb_id = g.id\r\n\t\tWHERE g.url != '' and g.sponsor_id = 0 and g.rgroup = 0 and status = 1 " . $_obfuscated_0D293F2D3B012A0107221A070818340238232517290E22_ . "\t\r\n\t\torder by gs.total_ctr desc \t", $rot_settings["db_link"]);
1561 while ($d = db_fetch_assoc($q)) {
1562 $_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_[] = (int) $d["url"];
1563 }
1564 if (count($_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_)) {
1565 $query .= "ORDER BY field(id, " . join(",", $_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_) . ") ";
1566 }
1567 } else {
1568 if ($type == "tag") {
1569 $_obfuscated_0D293F2D3B012A0107221A070818340238232517290E22_ = $rot_settings["linked_db_id"] ? " and source_url = '" . $rot_settings["linked_db_id"] . "' " : " and source_url = '' ";
1570 $_obfuscated_0D1B13073E233036373E342E0F3B261C0E160714373422_ = array();
1571 $q = db_query("SELECT gs.thumb_id, gi.url\r\n\t\tFROM rot_gallery_info AS gi\r\n\t\tJOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs on gs.gallery_id = gi.gallery_id\r\n\t\tJOIN rot_thumbs AS gt ON gt.gallery_id = gi.gallery_id\r\n\t\tJOIN rot_gallery_data1 AS gd ON gd.gallery_id = gi.gallery_id\r\n\t\tWHERE gi.gallery_type = 3 " . $_obfuscated_0D293F2D3B012A0107221A070818340238232517290E22_ . "\t\r\n\t\tAND gs.best_thumb = 'yes'\t\r\n\t\tORDER BY gs.total_ctr DESC\r\n\t\t", $rot_settings["db_link"]);
1572 while ($d = db_fetch_assoc($q)) {
1573 $_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_[] = (int) $d["url"];
1574 }
1575 if (array_count($_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_)) {
1576 $query .= " ORDER BY field(id, " . join(",", $_obfuscated_0D291612111C3B333B071103281B40282E293D1A151E01_) . ") ";
1577 }
1578 }
1579 }
1580 $q = db_query($query, $rot_settings["db_link"]);
1581 writelog("Total in set " . db_num_rows($q));
1582 while ($d = db_fetch_assoc($q)) {
1583 if (!$d["thumbs_list"]) {
1584 writelog("No active thumbs for item : " . $d["name"] . " ");
1585 continue;
1586 }
1587 $md5 = $type . $d["id"] . "_" . $rot_settings["linked_db_id"];
1588 if ($set_id) {
1589 $md5 .= "_" . $set_id;
1590 }
1591 $md5 = md5($md5);
1592 writelog("Select best " . $type . " for " . $d["name"] . " >> " . $thumb_shift . " (id: " . $d["id"] . ") (md5: " . $md5 . ")");
1593 $tmp = explode(",", $d["thumbs_list"]);
1594 $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ = $tmp[$thumb_shift];
1595 if (!$allow_dupes) {
1596 unset($_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_);
1597 for ($i = $thumb_shift; $i < count($tmp); $i++) {
1598 $id = $tmp[$i];
1599 if (!isset($_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_[$id])) {
1600 $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ = $id;
1601 break;
1602 }
1603 }
1604 if (!$_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_) {
1605 writelog("No unique thumb for it, skipping ...");
1606 continue;
1607 }
1608 }
1609 $best_item = db_get_row("select * from rot_gallery_info as gi\r\n LEFT JOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " as gs ON gs.gallery_id = gi.gallery_id\r\n LEFT JOIN rot_gallery_data" . $rot_settings["linked_description_id"] . " as gd ON gd.gallery_id = gi.gallery_id\r\n LEFT JOIN rot_thumbs as rt ON rt.gallery_id = gi.gallery_id\r\n WHERE gi.gallery_id = (SELECT gallery_id FROM rot_thumbs WHERE thumb_id = '" . $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ . "' ) \r\n and gs.thumb_id = '" . $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ . "' and rt.thumb_id = '" . $_obfuscated_0D0C3B01310F012C03132821102B23161D0F37371B1322_ . "'\r\n LIMIT 1", $rot_settings["db_link"]);
1610 $_obfuscated_0D2A021D360328010A2A26143606311905271A3E3C1322_[$best_item["thumb_id"]]++;
1611 $best_item["gallery_md5"] = $md5;
1612 $best_item["url"] = $d["id"];
1613 if ($type == "cat0") {
1614 $best_item["content"] = $_obfuscated_0D3F3F0F10361B3232293B0E301E2D30102D3502063011_[$d["id"]];
1615 }
1616 insert_cat0($best_item, $type, $set_id);
1617 }
1618 return true;
1619}
1620function delete_tested_thumbs($delete_tested_limit)
1621{
1622 global $rot_settings;
1623 writelog("Deleting tested thumbs");
1624 $_obfuscated_0D082628111D230C352615260F3C1A0D3F0F1F15331A32_ = array();
1625 $q = db_query("SELECT distinct(gallery_id), count(*) as total from rot_gallery_stats1 as gs\r\n\tWHERE gs.total_shows > '" . (int) $rot_settings["new_thumbs_shows"] . "'\r\n\tand gs.group_id != 0\r\n\tgroup by gallery_id HAVING total > " . (int) $delete_tested_limit);
1626 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1627 $_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_ = array();
1628 while ($d = db_fetch_assoc($q)) {
1629 $_obfuscated_0D3F0B0608255B0C2909170D3F322D2F37361B173C3E22_++;
1630 $_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_[] = $d["gallery_id"];
1631 if ($_obfuscated_0D3F0B0608255B0C2909170D3F322D2F37361B173C3E22_ % 100 == 0) {
1632 writelog("delete_tested_thumbs: checked " . $_obfuscated_0D3F0B0608255B0C2909170D3F322D2F37361B173C3E22_ . " of " . $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_);
1633 }
1634 if (500 < count($_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_)) {
1635 delete_tested_thumbs_process($_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_, $delete_tested_limit);
1636 $_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_ = array();
1637 }
1638 }
1639 if (count($_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_)) {
1640 delete_tested_thumbs_process($_obfuscated_0D1908040E112521091A3F2D2F40263E2913170E253B01_, $delete_tested_limit);
1641 }
1642 writelog("delete_tested_thumbs :: done");
1643}
1644function delete_tested_thumbs_process($gallery_ids, $delete_tested_limit)
1645{
1646 global $rot_settings;
1647 $_obfuscated_0D3B2D1C140D1D182E3B08162C0C352617031B29362632_ = "";
1648 $_obfuscated_0D320A3C125C1102130D310E2C1B321D352E0A2F0F0D22_ = $_obfuscated_0D3C283E0608292C110210363D3802120F1324230D3932_ = array();
1649 writelog("delete_tested_thumbs:: got following galleries with more then " . $delete_tested_limit . " thumbs : " . join(",", $gallery_ids));
1650 $_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_ = db_query("SELECT gallery_id, thumb_id, total_ctr FROM rot_gallery_stats1 AS gs\r\n\tWHERE total_shows > '" . (int) $rot_settings["new_thumbs_shows"] . "' \r\n\tAND group_id = 0\r\n\tAND gallery_id IN ('" . join("','", $gallery_ids) . "') \r\n\tORDER BY gallery_id, total_ctr DESC ");
1651 while ($d1 = db_fetch_assoc($_obfuscated_0D304035023F04353F123C0B2F3C2F025B3C3218262411_)) {
1652 if ($_obfuscated_0D3B2D1C140D1D182E3B08162C0C352617031B29362632_ != $d1["gallery_id"]) {
1653 $_obfuscated_0D3C283E0608292C110210363D3802120F1324230D3932_ = array();
1654 $_obfuscated_0D3B2D1C140D1D182E3B08162C0C352617031B29362632_ = $d1["gallery_id"];
1655 }
1656 $_obfuscated_0D3C283E0608292C110210363D3802120F1324230D3932_[] = $d1["thumb_id"];
1657 if (count($_obfuscated_0D3C283E0608292C110210363D3802120F1324230D3932_) <= $delete_tested_limit) {
1658 $_obfuscated_0D320A3C125C1102130D310E2C1B321D352E0A2F0F0D22_[] = $d1["thumb_id"];
1659 writelog("delete_tested_thumbs:: Save " . $d1["gallery_id"] . " - " . $d1["thumb_id"] . " ctr: " . $d1["total_ctr"]);
1660 } else {
1661 writelog("delete_tested_thumbs:: Delete " . $d1["gallery_id"] . " - " . $d1["thumb_id"] . " ctr: " . $d1["total_ctr"]);
1662 gallery_delete($d1["gallery_id"], "mark_delete_thumb", $d1["thumb_id"]);
1663 }
1664 }
1665}
1666function tube_init_thumbs()
1667{
1668 global $rot_settings;
1669 writelog("Init thumbs");
1670 $q = db_query("SELECT SQL_CALC_FOUND_ROWS gallery_id FROM `rot_gallery_info` ", $rot_settings["db_link"]);
1671 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1672 $gallery_ids = $_obfuscated_0D1D13182D5C3D1D2D2B2A1312333E171B2B5C1E313132_ = $_obfuscated_0D3F35020A083F32160B2F14212C273402023E25301B11_ = array();
1673 while ($d = db_fetch_assoc($q)) {
1674 if (!$_obfuscated_0D012D3523383135291210100A102E0F241D3F33231932_) {
1675 $_obfuscated_0D012D3523383135291210100A102E0F241D3F33231932_ = db_value("total", "SELECT FOUND_ROWS() as total", $rot_settings["db_link"]);
1676 }
1677 $gallery_ids[] = $d["gallery_id"];
1678 if (1000 <= count($gallery_ids)) {
1679 gallery_select_best_thumb($gallery_ids);
1680 $gallery_ids = array();
1681 $count += 1000;
1682 writelog((string) $count . " of " . $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_);
1683 }
1684 }
1685 if (count($gallery_ids)) {
1686 gallery_select_best_thumb($gallery_ids);
1687 }
1688 writelog("Init best thumb - done");
1689}
1690function interactive_google_translate()
1691{
1692 global $google_translate_languages;
1693 global $rot_settings;
1694 global $verbose;
1695 $verbose = 3;
1696 wraped_interactive_google_translate();
1697 $verbose = 0;
1698}
1699function wraped_interactive_google_translate()
1700{
1701 global $google_translate_languages;
1702 global $rot_settings;
1703 global $verbose;
1704 if (!function_exists("json_encode")) {
1705 exit("PHP lib JSON is not installed, you can not use translation services without it. Ask admin to install it for you \n\n");
1706 }
1707 if (!function_exists("curl_multi_init")) {
1708 exit("PHP lib CURL is not installed, you can not use translation services without it. Ask admin to install it for you \n\n");
1709 }
1710 writelog("You are about to translate some of your information. Note, this service is based on Google Translate and it's not free", false, false);
1711 writelog("You can press Ctrl-C to interrupt this action at any time ", false, false);
1712 $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_ = new prompt();
1713 if ($rot_settings["linked_db_id"] == 1 && 1 < linked_sites()) {
1714 writelog("This is a master site. You can translate texts for it as well as for any of linked sites. ", false, false);
1715 writelog("Hit enter to translate texts for master site or enter any of the following numbers if you want to translate text for a linked site: \n", false, false);
1716 foreach (linked_sites() as $site_id => $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_) {
1717 if (!$site_id) {
1718 continue;
1719 }
1720 writelog("Type " . $site_id . " for " . $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_["linked_db_name"] . " ", false, false);
1721 }
1722 if (true) {
1723 if ($_REQUEST["target_site_id"] && array_key_exists($_REQUEST["target_site_id"], linked_sites())) {
1724 $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ = $_REQUEST["target_site_id"];
1725 writelog("Settings site id to " . $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ . " \n", false, false);
1726 break;
1727 }
1728 $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("Enter id or just hit enter for master: ");
1729 if (trim($_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_) == "") {
1730 $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ = 1;
1731 }
1732 if ($_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ && !array_key_exists($_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_, linked_sites())) {
1733 writelog("Unknown id, try again \n", false, false);
1734 continue;
1735 }
1736 writelog("Selected site id: " . $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_);
1737 break;
1738 }
1739 } else {
1740 $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ = $rot_settings["linked_db_id"];
1741 writelog("We will translate information for THIS site ", false, false);
1742 if (true) {
1743 if ($_REQUEST["source_language"] && array_key_exists($_REQUEST["source_language"], $google_translate_languages)) {
1744 $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ = $_REQUEST["source_language"];
1745 writelog("Setting source_language to " . $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ . " \n", false, false);
1746 break;
1747 }
1748 $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("What is source language (2 chars code) ? type 'list' if you need a list : ");
1749 if ($_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ == "list") {
1750 foreach ($google_translate_languages as $k => $_obfuscated_0D2615172C3B02221A3E24321006121B0F400C0C123511_) {
1751 echo (string) $k . " => " . $_obfuscated_0D2615172C3B02221A3E24321006121B0F400C0C123511_ . " \n";
1752 }
1753 continue;
1754 } else {
1755 $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ = trim($_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_);
1756 if ($_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ == "") {
1757 writelog("source_language = autodetect");
1758 } else {
1759 if (!array_key_exists($_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, $google_translate_languages)) {
1760 print_r($google_translate_languages);
1761 writelog((string) $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ . " is not on list, please type 'list' to get a list of available languages \n", false, false);
1762 continue;
1763 }
1764 }
1765 break;
1766 }
1767 }
1768 }
1769 if ($_REQUEST["api_key"]) {
1770 $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ = $_REQUEST["api_key"];
1771 writelog("Setting api_key to " . $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ . " \n", false, false);
1772 } else {
1773 $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("What's your Google API key : ");
1774 }
1775 if (true) {
1776 if ($_REQUEST["target_entity"] && in_array($_REQUEST["target_entity"], array("categories", "galleries", "tags"))) {
1777 $_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ = $_REQUEST["target_entity"];
1778 writelog("Setting target_entity to " . $_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ . " \n", false, false);
1779 break;
1780 }
1781 $_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("What do you what to translate : categories, galleries or tags? ");
1782 if (!in_array($_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_, array("categories", "galleries", "tags"))) {
1783 writelog((string) $_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ . " is not on list, please check spelling \n", false, false);
1784 continue;
1785 }
1786 break;
1787 }
1788 if ($_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ === "galleries") {
1789 $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_ = array("alt" => "Alt (Title)", "description" => "Description", "custom_var1" => "Custom var1", "custom_var2" => "Custom var2", "custom_var3" => "Custom var3");
1790 if (!$rot_settings["linked_description_id"] && $rot_settings["linked_db_id"]) {
1791 writelog("Looks like this is a slave site, but it does not have separate descriptions. If you want to translate it you have to either translate it at the master or separate descriptions for this slave");
1792 return true;
1793 }
1794 if (true) {
1795 if ($_REQUEST["source_field"] && $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_[$_REQUEST["source_field"]]) {
1796 $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ = $_REQUEST["source_field"];
1797 writelog("Setting source_field to " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " \n", false, false);
1798 break;
1799 }
1800 $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("What field do you what to translate ? (Options: alt, description, custom_var1, custom_var2, custom_var3) ");
1801 if (!array_key_exists($_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_, $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_)) {
1802 writelog((string) $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " is not on list, please check spelling \n", false, false);
1803 continue;
1804 }
1805 break;
1806 }
1807 if (($_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ == "alt" || $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ == "description") && true) {
1808 if ($_REQUEST["update_slug"] && in_array($_REQUEST["update_slug"], array("yes", "no"))) {
1809 $_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ = $_REQUEST["update_slug"];
1810 writelog("Setting update_slug to " . $_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ . " \n", false, false);
1811 break;
1812 }
1813 $_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("Looks like you want to write to '" . $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ . "' field, do you want also update gallery slug ? (yes, no) ");
1814 if ($_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ != "yes" && $_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ != "no") {
1815 writelog("Please, choose either yes or no \n", false, false);
1816 continue;
1817 }
1818 if ($_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ == "no") {
1819 $_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_ = false;
1820 }
1821 break;
1822 }
1823 $_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_ = "google_translate_" . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . "_last_pos";
1824 if (!isset($rot_settings[$_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_])) {
1825 db_perform("rot_settings", array("name" => $_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_, "value" => 0));
1826 $rot_settings[$_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_] = 0;
1827 }
1828 if ($rot_settings[$_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_]) {
1829 if (true) {
1830 $_obfuscated_0D14232C0704290B303B5B261103161729123C033F1A01_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("You didn't finish translation last time, do you want to resume ? (yes - resume, no - start from the beginning): ");
1831 if ($_obfuscated_0D14232C0704290B303B5B261103161729123C033F1A01_ != "yes" && $_obfuscated_0D14232C0704290B303B5B261103161729123C033F1A01_ != "no") {
1832 writelog("Please, choose either yes or no \n", false, false);
1833 continue;
1834 }
1835 $_obfuscated_0D39343E1208342D352A3D103B0C1135253137210D1011_ = $_obfuscated_0D14232C0704290B303B5B261103161729123C033F1A01_ == "no" ? 0 : $rot_settings[$_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_];
1836 writelog("Starting from " . $_obfuscated_0D39343E1208342D352A3D103B0C1135253137210D1011_ . " \n", false, false);
1837 break;
1838 }
1839 } else {
1840 $_obfuscated_0D39343E1208342D352A3D103B0C1135253137210D1011_ = 0;
1841 }
1842 $count = 0;
1843 $q = db_query("SELECT gallery_id, " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " as source_string FROM rot_gallery_data" . $rot_settings["linked_description_id"] . " LIMIT " . (int) $_obfuscated_0D39343E1208342D352A3D103B0C1135253137210D1011_ . ", 99999999 ", $rot_settings["db_link"]);
1844 $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q);
1845 while ($d = db_fetch_assoc($q)) {
1846 if (trim($d["source_string"]) == "") {
1847 continue;
1848 }
1849 $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = google_translate($d["source_string"], $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_, $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_);
1850 if (!$_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) {
1851 writelog("Google traslation Engine returned an error, check your data \n\n", false, false);
1852 continue;
1853 }
1854 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = round($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
1855 if (!$count) {
1856 writelog("This is the first translated phrase, we paused a translation to show you results to make sure everything goes fine \n\n", false, false);
1857 writelog("Phrase : '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' \n", false, false);
1858 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter' , otherwise hit Ctrl-C to interupt the process and start all over");
1859 writelog("Ok, looks like everything's ok. \n", false, false);
1860 writelog("Do you want me to make a stop after each translation and ask for your confirmation or just silently go ahead ? ", false, false);
1861 writelog("Options: type 'stops' to make a stop after each phrase ", false, false);
1862 writelog("'log' - do not make stops but show each translated phrase ", false, false);
1863 writelog("'fast' - do not make stops, do not show translated phrases, just a percent of work done", false, false);
1864 if (true) {
1865 $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("Type your option (stops, log, fast): ");
1866 if (!in_array($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_, array("stops", "log", "fast"))) {
1867 writelog((string) $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ . " is not one of the options (stops, log, fast)", false, false);
1868 continue;
1869 }
1870 break;
1871 }
1872 } else {
1873 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "stops") {
1874 writelog("Gallery " . $d["gallery_id"] . " : " . $d["source_string"] . " was translated into " . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . " (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done)\n", false, false);
1875 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter', otherwise type how you want to translate it: ");
1876 if (2 < strlen($_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_)) {
1877 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_;
1878 } else {
1879 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = "";
1880 }
1881 } else {
1882 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "log") {
1883 writelog("Phrase : '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done) \n", false, false);
1884 } else {
1885 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = round($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
1886 echo "\r" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% translated ";
1887 }
1888 }
1889 }
1890 db_query("UPDATE rot_gallery_data" . $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ . " SET " . $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ . " = '" . addslashes($_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) . "' WHERE gallery_id = '" . $d["gallery_id"] . "' ", $rot_settings["db_link"]);
1891 if ($_obfuscated_0D02341B3C1F39021D5C252B2C3D3B3614191F1A2E3511_) {
1892 $_obfuscated_0D255C361C183C08011E192B0C043C380F1D2A02380B32_ = gallery_load($d["gallery_id"]);
1893 $_obfuscated_0D255C361C183C08011E192B0C043C380F1D2A02380B32_["linked_data"][$rot_settings["linked_description_id"]]["alt"] = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_;
1894 $_obfuscated_0D273B311C17123E5C3F1436290C1C0B331A2B10281F22_ = gallery_create_slug($_obfuscated_0D255C361C183C08011E192B0C043C380F1D2A02380B32_, $rot_settings["linked_description_id"]);
1895 db_query("UPDATE rot_gallery_data" . $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ . " SET gallery_slug = '" . addslashes($_obfuscated_0D273B311C17123E5C3F1436290C1C0B331A2B10281F22_) . "' WHERE gallery_id = '" . $d["gallery_id"] . "' ", $rot_settings["db_link"]);
1896 }
1897 if ($_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ != "11") {
1898 $tmp = load_url("http://cjwebmasters.com/translation_cache.php", array("method" => "post", "post_data" => array("source_phrase" => $d["source_string"], "google_result" => $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_, "user_result" => $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_, "source_lng" => $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, "target_lng" => $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_), "return_info" => true, "session_close" => true));
1899 }
1900 $count++;
1901 db_query("UPDATE rot_settings SET value = " . ($_obfuscated_0D39343E1208342D352A3D103B0C1135253137210D1011_ + $count) . " WHERE name = '" . $_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_ . "' ");
1902 }
1903 db_query("UPDATE rot_settings SET value = 0 WHERE name = '" . $_obfuscated_0D1B3B1026331E3F2A0D0C252A1E2F36261C0D292C3922_ . "' ");
1904 }
1905 if ($_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ === "tags") {
1906 $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_ = array("alt" => "Alt (Title)", "description" => "Description", "custom_var1" => "Custom var1", "custom_var2" => "Custom var2", "custom_var3" => "Custom var3");
1907 $_obfuscated_0D3D0601352D1A115B34351129242D3B40343436022432_ = $_obfuscated_0D2D13150309351935020A260836050A0F3B0E2F342111_ = array();
1908 $q = db_query("SELECT rot_linked_id, translation_lng FROM rot_linked_db WHERE not isnull(translation_lng) ");
1909 while ($d = db_fetch_assoc($q)) {
1910 $_obfuscated_0D3D0601352D1A115B34351129242D3B40343436022432_[$d["translation_lng"]] = $d["rot_linked_id"];
1911 $_obfuscated_0D2D13150309351935020A260836050A0F3B0E2F342111_[$d["rot_linked_id"]] = $d["translation_lng"];
1912 }
1913 if ($_obfuscated_0D3D0601352D1A115B34351129242D3B40343436022432_[$_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_] != $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_) {
1914 writelog("You want to translate from " . $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_ . " to " . $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_ . ", while this slave it marked as " . $_obfuscated_0D2D13150309351935020A260836050A0F3B0E2F342111_[$_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_] . ", looks like this is an error ");
1915 return NULL;
1916 }
1917 $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ = "tag_name";
1918 $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ = "tag_name" . $_obfuscated_0D3D0601352D1A115B34351129242D3B40343436022432_[$_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_];
1919 $count = 0;
1920 $q = db_query("SELECT tag_id, " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " as source_string FROM rot_tags", $rot_settings["db_link"]);
1921 for ($_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q); $d = db_fetch_assoc($q); $count++) {
1922 if (trim($d["source_string"]) == "") {
1923 continue;
1924 }
1925 $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = google_translate($d["source_string"], $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_, $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_);
1926 if (!$_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) {
1927 writelog("Google traslation Engine returned an error, check your data \n\n", false, false);
1928 exit;
1929 }
1930 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = round($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
1931 if (!$count) {
1932 writelog("This is the first translated phrase, we paused a translation to show you results to make sure everything goes fine \n\n", false, false);
1933 writelog("Phrase : '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' \n", false, false);
1934 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter' , otherwise hit Ctrl-C to interupt the process and start all over");
1935 writelog("Ok, looks like everything's ok. \n", false, false);
1936 writelog("Do you want me to make a stop after each translation and ask for your confirmation or just silently go ahead ? ", false, false);
1937 writelog("Options: type 'stops' to make a stop after each phrase ", false, false);
1938 writelog("'log' - do not make stops but show each translated phrase ", false, false);
1939 writelog("'fast' - do not make stops, do not show translated phrases, just a percent of work done", false, false);
1940 if (true) {
1941 $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("Type your option (stops, log, fast): ");
1942 if (!in_array($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_, array("stops", "log", "fast"))) {
1943 writelog((string) $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ . " is not one of the options (stops, log, fast)", false, false);
1944 continue;
1945 }
1946 break;
1947 }
1948 } else {
1949 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "stops") {
1950 writelog("Tag " . $d["tag_name"] . " : " . $d["source_string"] . " was translated into " . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . " (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done)\n", false, false);
1951 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter', otherwise type how you want to translate it: ");
1952 if (2 < strlen($_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_)) {
1953 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_;
1954 } else {
1955 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = "";
1956 }
1957 } else {
1958 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "log") {
1959 writelog("Phrase : '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done) \n", false, false);
1960 } else {
1961 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = round($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
1962 echo "\r" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% translated ";
1963 }
1964 }
1965 }
1966 db_query("UPDATE rot_tags SET " . $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ . " = '" . addslashes($_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) . "' WHERE tag_id = '" . $d["tag_id"] . "' ", $rot_settings["db_link"]);
1967 if ($_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ != "11") {
1968 $tmp = load_url("http://cjwebmasters.com/translation_cache.php", array("method" => "post", "post_data" => array("source_phrase" => $d["source_string"], "google_result" => $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_, "user_result" => $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_, "source_lng" => $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, "target_lng" => $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_), "return_info" => true, "session_close" => true));
1969 }
1970 }
1971 }
1972 if ($_obfuscated_0D27142F0E060C2B1F2C2D33060A1B2F37281D17301132_ === "categories") {
1973 $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_ = array("custom_name" => "Custom name", "description" => "Description", "group_keywords" => "Group meta keywords", "group_custom_var1" => "Custom var1", "group_custom_var2" => "Custom var2", "group_custom_var3" => "Custom var3");
1974 if (true) {
1975 if ($_REQUEST["source_field"] && $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_[$_REQUEST["source_field"]]) {
1976 $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ = $_REQUEST["source_field"];
1977 writelog("Setting source_field to " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " \n", false, false);
1978 break;
1979 }
1980 $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("What field do you what to translate ? (Options: custom_name, description, group_keywords, group_custom_var1, group_custom_var2, group_custom_var3) ");
1981 if (!array_key_exists($_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_, $_obfuscated_0D2F37092833092A052716393D2725250D1E022C0E1032_)) {
1982 writelog((string) $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " is not on list, please check spelling \n", false, false);
1983 continue;
1984 }
1985 break;
1986 }
1987 $count = 0;
1988 $q = db_query("SELECT group_id, " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . " as source_string FROM rot_groups_data WHERE site_id = '" . (int) $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ . "' ", $rot_settings["db_link"]);
1989 for ($_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ = db_num_rows($q); $d = db_fetch_assoc($q); $count++) {
1990 if ($_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ == "custom_name" && trim($d["source_string"]) == "") {
1991 $d["source_string"] = db_val("SELECT name FROM rot_groups WHERE id = '" . $d["group_id"] . "' ", $rot_settings["db_link"]);
1992 }
1993 if (trim($d["source_string"]) == "") {
1994 continue;
1995 }
1996 $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = google_translate($d["source_string"], $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_, $_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_);
1997 if (!$_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) {
1998 writelog("Google traslation Engine returned an error, check your data \n\n", false, false);
1999 exit;
2000 }
2001 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = ceil($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
2002 if (!$count) {
2003 writelog("This is the first translated phrase, we paused the process to show you results to make sure everything goes fine \n\n", false, false);
2004 writelog("Phrase : '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' \n", false, false);
2005 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter' , otherwise hit Ctrl-C to interupt the process and start all over");
2006 writelog("Ok, looks like everything's ok. \n", false, false);
2007 writelog("Do you want me to make a stop after each translation and ask for your confirmation or just silently go ahead ? ", false, false);
2008 writelog("Options: type 'stops' to make a stop after each phrase ", false, false);
2009 writelog("'log' - do not make stops but show each translated phrase ", false, false);
2010 writelog("'fast' - do not make stops, do not show translated phrases, just a percent of work done", false, false);
2011 if (true) {
2012 $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("Type your option (stops, log, fast): ");
2013 if (!in_array($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_, array("stops", "log", "fast"))) {
2014 writelog((string) $_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ . " is not one of the options (stops, log, fast)", false, false);
2015 continue;
2016 }
2017 break;
2018 }
2019 } else {
2020 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "stops") {
2021 writelog("Category " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . ": '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done)\n", false, false);
2022 $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_ = $_obfuscated_0D3D3E193F221E362A132B300F0B121D121F0914100522_->get("If everything's ok - just hit 'enter', otherwise type how you want to translate it: ");
2023 if (2 < strlen($_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_)) {
2024 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ = $_obfuscated_0D2E3F212D14033D093029340B163B102D01052E250C32_;
2025 } else {
2026 $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_ = "";
2027 }
2028 } else {
2029 if ($_obfuscated_0D331116403C3F100838040437331109391936373E3F22_ == "log") {
2030 writelog("Category " . $_obfuscated_0D5B38183B1313383B1A225C0D1D3D033D1A033E3B0F11_ . ": '" . $d["source_string"] . "' was translated into '" . $_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_ . "' (" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% done) \n", false, false);
2031 } else {
2032 $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ = ceil($count / $_obfuscated_0D35273816073512393116391A07353E22223E3E3F2A22_ * 100);
2033 echo "\r" . $_obfuscated_0D2D29311B022D1E2801231C111F2318382C280C0C3C22_ . "% translated ";
2034 }
2035 }
2036 }
2037 db_query("UPDATE rot_groups_data SET " . $_obfuscated_0D2E260B212A0806163E1533101B3731272221370B2611_ . " = '" . addslashes($_obfuscated_0D1917043E2C223213273E32350C0401141F131A025C32_) . "' WHERE group_id = '" . $d["group_id"] . "' and site_id = '" . (int) $_obfuscated_0D0E0438212940110F0B0E082D0822100D1A0438063811_ . "' ", $rot_settings["db_link"]);
2038 if ($_obfuscated_0D5C1A083E18321D2B12260E152F331032301921290322_ != "11") {
2039 $tmp = load_url("http://cjwebmasters.com/translation_cache.php", array("method" => "post", "post_data" => array("source_phrase" => $d["source_string"], "google_result" => $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_, "user_result" => $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_, "source_lng" => $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, "target_lng" => $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_), "return_info" => true, "session_close" => true));
2040 }
2041 }
2042 }
2043}
2044function google_translate($text, $source_lng, $target_lng, $api_key, $save_result = false)
2045{
2046 if ($api_key == "11") {
2047 return $text ? $text . "_" . $target_lng : "";
2048 }
2049 if ($api_key == "API_KEY_FROM_GOOGLE") {
2050 $tmp = array("status" => 200, "body" => file_get_contents("../../1.txt"));
2051 } else {
2052 $_obfuscated_0D2E1012210601231730402617110D5C27323022065B01_ = "https://www.googleapis.com/language/translate/v2?key=" . $api_key;
2053 if ($source_lng) {
2054 $_obfuscated_0D2E1012210601231730402617110D5C27323022065B01_ .= "&source=" . $source_lng;
2055 }
2056 $_obfuscated_0D2E1012210601231730402617110D5C27323022065B01_ .= "&target=" . $target_lng . "&q=" . urlencode($text);
2057 $tmp = load_url($_obfuscated_0D2E1012210601231730402617110D5C27323022065B01_, array("return_info" => true));
2058 }
2059 $data = json_decode($tmp["body"]);
2060 if ($tmp["status"] != 200) {
2061 writelog("Not 200 status from translation engine (" . $tmp["status"] . ") " . $tmp["body"] . " (" . $_obfuscated_0D2E1012210601231730402617110D5C27323022065B01_ . ")");
2062 return false;
2063 }
2064 if ($save_result) {
2065 $tmp = load_url("http://cjwebmasters.com/translation_cache.php", array("method" => "post", "post_data" => array("source_phrase" => $d["source_string"], "google_result" => $_obfuscated_0D3E2B121403040D0E1825263115351D182D1F38151F11_, "user_result" => $_obfuscated_0D0A122A0A0E0B24101539103016171F1A1F3C3F1F3611_, "source_lng" => $_obfuscated_0D21051539013B150A2D012D24042F07111712010A2832_, "target_lng" => $_obfuscated_0D3E311B0222051F233710020A1D0F0B250C2610222432_), "return_info" => true, "session_close" => true));
2066 }
2067 return preg_replace("!\\s+!", " ", urldecode($data->data->translations[0]->translatedText));
2068}
2069function create_extra_thumbs()
2070{
2071 global $verbose;
2072 global $rot_settings;
2073 set_time_limit(0);
2074 include_once "../includes/libs/http_functions.php";
2075 include_once "../includes/libs/img_functions.php";
2076 if (!in_array($_REQUEST["extra_thumb"], array(1, 2, 3))) {
2077 exit("create_extra_thumbs format : php rotation.php action=create_extra_thumbs extra_thumb=1(2 or 3) crop_profile_id=(name of crop profile) ");
2078 }
2079 if (!($_obfuscated_0D281E112F06191326363F2210171D393E0D1612142A11_ = db_get_row("SELECT * FROM rot_crop_profiles WHERE name = '" . addslashes($_REQUEST["crop_profile"]) . "' "))) {
2080 exit("Can not find crop profile '" . $_REQUEST["crop_profile"] . "' ");
2081 }
2082 $_obfuscated_0D281E112F06191326363F2210171D393E0D1612142A11_ = $_obfuscated_0D281E112F06191326363F2210171D393E0D1612142A11_ + $rot_settings;
2083 $verbose = 3;
2084 $_obfuscated_0D152914112D1029403732181E0F5B3E25283E2F0C0932_ = $_REQUEST["continue"] ? db_val("SELECT value FROM functions_data WHERE name = 'create_extra_thumbs' ") : 0;
2085 db_perform("functions_data", array("name" => "create_extra_thumbs", "value" => $_obfuscated_0D152914112D1029403732181E0F5B3E25283E2F0C0932_), "insert_ignore");
2086 $q = db_query("SELECT thumb_id, source_thumb_url FROM rot_thumbs WHERE thumb_status = 'active' and thumb_id > " . (int) $_obfuscated_0D152914112D1029403732181E0F5B3E25283E2F0C0932_ . " ORDER BY thumb_id ");
2087 $_obfuscated_0D38101035192124161D3F1C3719293138243C16383132_ = db_num_rows($q);
2088 while ($d = db_fetch_assoc($q)) {
2089 if (get_memory_limit() * 0.9 < memory_get_usage()) {
2090 echo "Memory usage limit, please rerun the script as \n";
2091 echo "php " . join(" ", $_SERVER["argv"]) . " continue=true \n\n";
2092 return NULL;
2093 }
2094 db_query("UPDATE functions_data SET value = '" . $d["thumb_id"] . "' WHERE name = 'create_extra_thumbs' ");
2095 $count++;
2096 if (!$d["source_thumb_url"]) {
2097 continue;
2098 }
2099 $_obfuscated_0D2E195B3E21220728400D15240A23133D0B0E32282822_ = "../tmp/recrop_extra_thumb.jpg";
2100 writelog("Downloading " . $d["source_thumb_url"]);
2101 if (!DownloadFile($d["source_thumb_url"], $_obfuscated_0D2E195B3E21220728400D15240A23133D0B0E32282822_)) {
2102 print "Create_extra_thumbs : can not DL " . $d["source_thumb_url"] . " , skipping ... \n";
2103 continue;
2104 }
2105 $_obfuscated_0D0F261B2E3C272F0827125B233C5B390E352903013532_ = $_obfuscated_0D2E195B3E21220728400D15240A23133D0B0E32282822_ . ".extra." . $_obfuscated_0D281E112F06191326363F2210171D393E0D1612142A11_["grabber_thumb_format"];
2106 $_obfuscated_0D1635041F05160324185C40310C3009332C2836273D11_ = make_thumb($_obfuscated_0D2E195B3E21220728400D15240A23133D0B0E32282822_, $_obfuscated_0D0F261B2E3C272F0827125B233C5B390E352903013532_, $_obfuscated_0D281E112F06191326363F2210171D393E0D1612142A11_);
2107 if ($_obfuscated_0D1635041F05160324185C40310C3009332C2836273D11_ === false) {
2108 print "Can not make thumb " . $_obfuscated_0D2E195B3E21220728400D15240A23133D0B0E32282822_ . " \n";
2109 continue;
2110 }
2111 writelog("Saving extra thumb " . $d["thumb_id"] . " ");
2112 $_obfuscated_0D303513011B2B0B3E3D2B1326303E24243E37132F1111_ = $_REQUEST["extra_thumb"] == 1 ? "" : (int) $_REQUEST["extra_thumb"];
2113 rot_save($rot_settings + array("path_add_folder" => "extra_thumb" . $_obfuscated_0D303513011B2B0B3E3D2B1326303E24243E37132F1111_, "force_file_extension" => "jpg"), $_obfuscated_0D0F261B2E3C272F0827125B233C5B390E352903013532_, $d["thumb_id"]);
2114 if ($count % 100 == 0) {
2115 echo "Done " . $count . " of " . $_obfuscated_0D38101035192124161D3F1C3719293138243C16383132_ . " \n";
2116 }
2117 }
2118}
2119function update_models_cache()
2120{
2121 global $rot_settings;
2122 if ($rot_settings["select_model_best_thumb"] == 0) {
2123 return NULL;
2124 }
2125 writelog("Updating model_total_galleries ");
2126 $_obfuscated_0D1925272A272F3C330B0D401A2C350718111E16030132_ = array($rot_settings["linked_db_id"]);
2127 foreach (linked_sites() as $site_id => $_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_) {
2128 if ($_obfuscated_0D37181F160F383805302F3E1938071739240A381E3F22_["translation_source"] == $rot_settings["linked_db_id"]) {
2129 $_obfuscated_0D1925272A272F3C330B0D401A2C350718111E16030132_[] = $site_id;
2130 }
2131 }
2132 db_query("UPDATE rot_models_data\r\n\r\n\tINNER JOIN (SELECT model_id, SUM( gs.total_ctr)/count(gi.gallery_id) AS total_ctr, count(gi.gallery_id) as total_galleries\r\n\tFROM rot_gal2model AS g2m \r\n\tLEFT JOIN rot_gallery_info AS gi ON gi.gallery_id = g2m.gallery_id\r\n\tLEFT JOIN rot_gallery_stats" . $rot_settings["linked_db_id"] . " AS gs ON gs.gallery_id = gi.gallery_id and gs.best_thumb = 'yes'\r\n\tWHERE gi.gallery_status = 'active' \r\n\tGROUP BY model_id) as tmp\r\n\r\n\tON (rot_models_data.model_id = tmp.model_id and rot_models_data.site_id IN (" . join(",", $_obfuscated_0D1925272A272F3C330B0D401A2C350718111E16030132_) . ") )\r\n\tSET rot_models_data.model_total_galleries = tmp.total_galleries, rot_models_data.model_average_ctr = tmp.total_ctr\r\n\t", $rot_settings["db_link"]);
2133}
2134function empty_tmp_folder()
2135{
2136}
2137function assign_groups_by_tags()
2138{
2139 global $rot_settings;
2140 if ($rot_settings["linked_db_id"] != 1) {
2141 return NULL;
2142 }
2143 $_obfuscated_0D3B0E1106092F1B35152A5B2807113819090C0B060111_ = $GLOBALS["config"]["debug"];
2144 $GLOBALS["config"]["debug"] = false;
2145 writelog("Assign groups for galleries based on tags :: Start");
2146 $_obfuscated_0D3C210A0C222E160D061A210C2F27143110331E1B3E01_ = array();
2147 $q = db_query("SELECT * from rot_tags ");
2148 while ($d = db_fetch_assoc($q)) {
2149 $_obfuscated_0D1801171401252F37252A2B330C290E1238025C5B3011_[$d["tag_id"]] = $d["tag_name"];
2150 }
2151 $group2id = array();
2152 $q = db_query("SELECT id, name from rot_groups ");
2153 while ($d = db_fetch_assoc($q)) {
2154 $group2id[$d["name"]] = $d["id"];
2155 $group2id[strtolower($d["name"])] = $d["id"];
2156 }
2157 $q = db_query("SELECT gallery_id, GROUP_CONCAT(tag_id) as tag_ids FROM `rot_gal2tag` WHERE site_id = 1 group by gallery_id");
2158 $_obfuscated_0D1C050E2F3F3404283B36083E5B1416281831211B0232_ = db_num_rows($q);
2159 while ($d = db_fetch_assoc($q)) {
2160 $count++;
2161 if ($count % 100 == 0) {
2162 writelog("Assign groups: " . $count . " of " . $_obfuscated_0D1C050E2F3F3404283B36083E5B1416281831211B0232_);
2163 }
2164 $_obfuscated_0D3E1D0119010F295C0812040B210D0B2D03321A1A3001_ = array();
2165 foreach (explode(",", $d["tag_ids"]) as $z => $_obfuscated_0D0D0E3B403C0819161B1D2D0E12120B2C300939283311_) {
2166 if (!$group2id[$_obfuscated_0D1801171401252F37252A2B330C290E1238025C5B3011_[$_obfuscated_0D0D0E3B403C0819161B1D2D0E12120B2C300939283311_]]) {
2167 continue;
2168 }
2169 $_obfuscated_0D3E1D0119010F295C0812040B210D0B2D03321A1A3001_[] = $group2id[$_obfuscated_0D1801171401252F37252A2B330C290E1238025C5B3011_[$_obfuscated_0D0D0E3B403C0819161B1D2D0E12120B2C300939283311_]];
2170 }
2171 gallery_set_groups($d["gallery_id"], $_obfuscated_0D3E1D0119010F295C0812040B210D0B2D03321A1A3001_);
2172 }
2173 writelog("Assign groups: Done");
2174 $GLOBALS["config"]["debug"] = $_obfuscated_0D3B0E1106092F1B35152A5B2807113819090C0B060111_;
2175 return true;
2176}
2177function process_extra_functions()
2178{
2179 if ($_GET["action"] == "translate_text") {
2180 echo google_translate(urlencode($_GET["text"]), $_GET["source_lng"], $_GET["target_lng"], $_GET["api_key"], true);
2181 exit;
2182 }
2183 if ($_REQUEST["action"] == "translate") {
2184 interactive_google_translate();
2185 exit;
2186 }
2187 if ($_REQUEST["action"] == "create_extra_thumbs" && !$_SERVER["REMOTE_ADDR"]) {
2188 create_extra_thumbs();
2189 exit;
2190 }
2191}
2192function check_search_queries()
2193{
2194 global $rot_settings;
2195 $_obfuscated_0D3B2D1C140D1D182E3B08162C0C352617031B29362632_ = $rot_settings["check_search_queries_last_id"] ? (int) $rot_settings["check_search_queries_last_id"] : 0;
2196 $_obfuscated_0D2E1C300131073601250A0337262D291A19041E211822_ = 10000;
2197 $res = array();
2198 writelog("Check search queries (last_id " . $_obfuscated_0D3B2D1C140D1D182E3B08162C0C352617031B29362632_ . ") ");
2199 $q = db_query("SELECT sq_id, search_query FROM rot_search_queries WHERE hits = 0 LIMIT " . $_obfuscated_0D2E1C300131073601250A0337262D291A19041E211822_);
2200 while ($d = db_fetch_assoc($q)) {
2201 $_obfuscated_0D021C102A01381E10271C2C39160A233F241B113E3911_ = $d["search_query"];
2202 $count++;
2203 if ($count % 100 == 0) {
2204 writelog("Checked " . $count . " ");
2205 }
2206 $_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_ = array("search" => $_obfuscated_0D021C102A01381E10271C2C39160A233F241B113E3911_);
2207 $_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_ = rot_get_items_prepare_query($_obfuscated_0D3D1826042A1F0B2336232B2B401418383D360F0B3622_, 0, 1, $rot_settings, false);
2208 $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_ = rot_get_item_execute_query($_obfuscated_0D09145C335C2A250A0C12121926101F07141319323322_, $_obfuscated_0D19043F1738123F08363E292D1D363909121334350922_, $rot_settings);
2209 if ($_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["total"] == 0) {
2210 writelog("Search query " . $_obfuscated_0D021C102A01381E10271C2C39160A233F241B113E3911_ . " returned 0 results, deleting query ");
2211 db_query("DELETE FROM rot_search_queries WHERE search_query = '" . addslashes($_obfuscated_0D021C102A01381E10271C2C39160A233F241B113E3911_) . "' ");
2212 } else {
2213 db_query("UPDATE rot_search_queries SET items_found = '" . $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["total"] . "', gal_id = '" . $_obfuscated_0D2B5C2903101D3740405C330F103C370610150B162C32_["items"][0]["gallery_id"] . "', hits = hits + 1 \r\n\t\t\tWHERE search_query = '" . addslashes($_obfuscated_0D021C102A01381E10271C2C39160A233F241B113E3911_) . "' ");
2214 }
2215 }
2216}
2217function check_double_run()
2218{
2219 global $rot_settings;
2220 if (strtoupper(substr(PHP_OS, 0, 3)) === "WIN") {
2221 if ($rot_settings["rot_cron_running"]) {
2222 if ($rot_settings["rot_cron_running"] < time() - 60 * 5) {
2223 db_query("UPDATE rot_settings SET value = '" . time() . "' WHERE name = 'rot_cron_running' ");
2224 } else {
2225 writelog("Old copy still running from " . date("H:i:s", $rot_settings["rot_cron_running"]));
2226 exit;
2227 }
2228 } else {
2229 db_query("INSERT INTO rot_settings (name, value) VALUES ('rot_cron_running', '" . time() . "') ON DUPLICATE KEY UPDATE value = " . time());
2230 db_query("INSERT INTO rot_settings (name, value) VALUES ('rot_last_run', '" . time() . "') ON DUPLICATE KEY UPDATE value = " . time());
2231 }
2232 } else {
2233 if ($rot_settings["rot_cron_running"]) {
2234 $_obfuscated_0D140A3E311C40080812075B332E0D2721292810371132_ = explode(PHP_EOL, shell_exec("ps -e | awk '{print \$1}'"));
2235 if (in_array($rot_settings["rot_cron_running"], $_obfuscated_0D140A3E311C40080812075B332E0D2721292810371132_)) {
2236 writelog("Old copy (pid " . $rot_settings["rot_cron_running"] . ") still running");
2237 exit;
2238 }
2239 } else {
2240 db_query("INSERT INTO rot_settings (name, value) VALUES ('rot_cron_running', '" . getmypid() . "') ON DUPLICATE KEY UPDATE value = " . getmypid());
2241 db_query("INSERT INTO rot_settings (name, value) VALUES ('rot_last_run', '" . time() . "') ON DUPLICATE KEY UPDATE value = " . time());
2242 }
2243 }
2244}
2245
2246?>