{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/89992359","pull_request_review_id":10517209,"id":89992359,"diff_hunk":"@@ -0,0 +1,205 @@\n+#include \"indexer/banners.hpp\"\n+\n+#include \"coding/reader_streambuf.hpp\"\n+#include \"indexer/classificator.hpp\"\n+#include \"platform/platform.hpp\"\n+#include \"base/string_utils.hpp\"\n+\n+namespace\n+{\n+// Convert ISO date to unix time.\n+bool StringToTimestamp(string const & s, time_t & result)\n+{\n+  vector<string> dateParts;\n+  strings::ParseCSVRow(s, '-', dateParts);\n+  if (dateParts.size() != 3)\n+    return false;\n+\n+  // Initializing structure to zero hours and minutes, but with proper tm_isdst.\n+  time_t const localTime = std::time(nullptr);\n+  tm * time = localtime(&localTime);\n+  time->tm_sec = time->tm_min = time->tm_hour = 0;\n+\n+  if (!strings::to_int(dateParts[0], time->tm_year))\n+    return false;\n+  if (time->tm_year < 2016)  // Fail dates with year 2015 and older.\n+    return false;\n+  time->tm_year -= 1900;\n+\n+  if (!strings::to_int(dateParts[1], time->tm_mon))\n+    return false;\n+  if (time->tm_mon < 1 || time->tm_mon > 12)\n+    return false;\n+  time->tm_mon -= 1;\n+\n+  if (!strings::to_int(dateParts[2], time->tm_mday))\n+    return false;\n+  if (time->tm_mday < 1 || time->tm_mday > 31)\n+    return false;\n+\n+  time_t timestamp = mktime(time);\n+  if (timestamp < 0)\n+    return false;\n+\n+  result = timestamp;\n+  return true;\n+}\n+}  // namespace\n+\n+namespace banner\n+{\n+string Banner::GetVariableValue(string const & name) const\n+{\n+  if (name == \"lang\")\n+    return \"ru\";  // TODO(@zverik): this variable, {mwmlang}, {country} etc.\n+  else\n+  {\n+    auto const property = m_properties.find(name);\n+    if (property != m_properties.end())\n+      return property->second;\n+  }\n+  return {};\n+}\n+\n+Banner::Banner(string const & id) : m_id(id)\n+{\n+  m_messageBase = \"banner_\" + id;\n+  m_iconName = m_messageBase + \".png\";\n+  m_defaultUrl = \"\";\n+  m_activeAfter = time(nullptr);\n+  m_activeBefore = 0;\n+}\n+\n+bool Banner::IsActive() const\n+{\n+  if (IsEmpty())\n+    return false;\n+  time_t const now = time(nullptr);\n+  return now >= m_activeAfter && (m_activeBefore == 0 || now < m_activeBefore);\n+}\n+\n+void Banner::SetProperty(string const & name, string const & value)\n+{\n+  if (name == \"messages\")\n+    m_messageBase = value;\n+  else if (name == \"icon\")\n+    m_iconName = value;\n+  else if (name == \"url\")\n+  {\n+    CHECK(strings::StartsWith(value, \"http://\") || strings::StartsWith(value, \"https://\"),\n+          (\"URL without a protocol for banner\", m_id));\n+    m_defaultUrl = value;\n+  }\n+  else if (name == \"start\")\n+    CHECK(StringToTimestamp(value, m_activeAfter),\n+          (\"Wrong start date\", value, \"for banner\", m_id));\n+  else if (name == \"end\")\n+  {\n+    CHECK(StringToTimestamp(value, m_activeBefore),\n+          (\"Wrong end date\", value, \"for banner\", m_id));\n+    m_activeBefore += 24 * 60 * 60; // Add a day so we don't miss one\n+  }\n+  else\n+    m_properties[name] = value;\n+}\n+\n+string Banner::GetFormattedUrl(string const & url) const\n+{\n+  string baseUrl = url.empty() ? m_defaultUrl : url;\n+  auto start = baseUrl.find('{');\n+  while (start != string::npos)\n+  {\n+    auto end = baseUrl.find('}', start + 1);\n+    if (end == string::npos)\n+      break;\n+    string value = GetVariableValue(baseUrl.substr(start + 1, end - start - 1));\n+    if (!value.empty())\n+    {\n+      baseUrl.replace(start, end - start + 1, value);\n+      end -= end - start + 1 - value.length();\n+    }\n+    start = baseUrl.find('{', end + 1);\n+  }\n+  return baseUrl;\n+}\n+\n+void BannerSet::ReadBanners(istream & s)\n+{\n+  m_banners.clear();\n+\n+  Banner banner;\n+  int lineNumber = 1;\n+  for (string line; getline(s, line); ++lineNumber)\n+  {\n+    strings::Trim(line);\n+    if (line.empty() || line.front() == '#')\n+      continue;\n+\n+    auto const equals = line.find('=');\n+    if (equals == string::npos)\n+    {\n+      // Section header, should be in square brackets.\n+      CHECK(line.front() == '[' && line.back() == ']', (\"Unknown syntax at line\", lineNumber));\n+      strings::Trim(line, \" \\t[]\");","path":"indexer/banners.cpp","position":143,"original_position":143,"commit_id":"1b9869ab995171845f1ccf9fe22674ba63aba6aa","original_commit_id":"1b9869ab995171845f1ccf9fe22674ba63aba6aa","user":{"login":"milchakov","id":2606569,"avatar_url":"https://avatars.githubusercontent.com/u/2606569?v=3","gravatar_id":"","url":"https://api.github.com/users/milchakov","html_url":"https://github.com/milchakov","followers_url":"https://api.github.com/users/milchakov/followers","following_url":"https://api.github.com/users/milchakov/following{/other_user}","gists_url":"https://api.github.com/users/milchakov/gists{/gist_id}","starred_url":"https://api.github.com/users/milchakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milchakov/subscriptions","organizations_url":"https://api.github.com/users/milchakov/orgs","repos_url":"https://api.github.com/users/milchakov/repos","events_url":"https://api.github.com/users/milchakov/events{/privacy}","received_events_url":"https://api.github.com/users/milchakov/received_events","type":"User","site_admin":false},"body":"отбой, понял","created_at":"2016-11-29T11:38:11Z","updated_at":"2016-11-29T11:38:11Z","html_url":"https://github.com/mapsme/omim/pull/4828#discussion_r89992359","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/4828","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/89992359"},"html":{"href":"https://github.com/mapsme/omim/pull/4828#discussion_r89992359"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4828"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/4828","id":95581508,"html_url":"https://github.com/mapsme/omim/pull/4828","diff_url":"https://github.com/mapsme/omim/pull/4828.diff","patch_url":"https://github.com/mapsme/omim/pull/4828.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/4828","number":4828,"state":"open","locked":false,"title":"[DNM][banners] Add banners infrastructure","user":{"login":"Zverik","id":766031,"avatar_url":"https://avatars.githubusercontent.com/u/766031?v=3","gravatar_id":"","url":"https://api.github.com/users/Zverik","html_url":"https://github.com/Zverik","followers_url":"https://api.github.com/users/Zverik/followers","following_url":"https://api.github.com/users/Zverik/following{/other_user}","gists_url":"https://api.github.com/users/Zverik/gists{/gist_id}","starred_url":"https://api.github.com/users/Zverik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zverik/subscriptions","organizations_url":"https://api.github.com/users/Zverik/orgs","repos_url":"https://api.github.com/users/Zverik/repos","events_url":"https://api.github.com/users/Zverik/events{/privacy}","received_events_url":"https://api.github.com/users/Zverik/received_events","type":"User","site_admin":false},"body":"Поле в метаданных для кастомной ссылки и список данных для каждого баннера из файла `banners.txt`. Добавил чтение файла во фреймворк и использование данных в `place_page_info`.\r\n\r\nПока стоит DNM: не дописал тесты и не проверил на живых данных. Тем не менее, код компилируется и требует проверки.","created_at":"2016-11-28T21:38:59Z","updated_at":"2016-11-29T11:38:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b70d83d340c2783dae4307133d71cbde83dc274","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/4828/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/4828/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/4828/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/1b9869ab995171845f1ccf9fe22674ba63aba6aa","head":{"label":"Zverik:banners","ref":"banners","sha":"1b9869ab995171845f1ccf9fe22674ba63aba6aa","user":{"login":"Zverik","id":766031,"avatar_url":"https://avatars.githubusercontent.com/u/766031?v=3","gravatar_id":"","url":"https://api.github.com/users/Zverik","html_url":"https://github.com/Zverik","followers_url":"https://api.github.com/users/Zverik/followers","following_url":"https://api.github.com/users/Zverik/following{/other_user}","gists_url":"https://api.github.com/users/Zverik/gists{/gist_id}","starred_url":"https://api.github.com/users/Zverik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zverik/subscriptions","organizations_url":"https://api.github.com/users/Zverik/orgs","repos_url":"https://api.github.com/users/Zverik/repos","events_url":"https://api.github.com/users/Zverik/events{/privacy}","received_events_url":"https://api.github.com/users/Zverik/received_events","type":"User","site_admin":false},"repo":{"id":43427426,"name":"omim","full_name":"Zverik/omim","owner":{"login":"Zverik","id":766031,"avatar_url":"https://avatars.githubusercontent.com/u/766031?v=3","gravatar_id":"","url":"https://api.github.com/users/Zverik","html_url":"https://github.com/Zverik","followers_url":"https://api.github.com/users/Zverik/followers","following_url":"https://api.github.com/users/Zverik/following{/other_user}","gists_url":"https://api.github.com/users/Zverik/gists{/gist_id}","starred_url":"https://api.github.com/users/Zverik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zverik/subscriptions","organizations_url":"https://api.github.com/users/Zverik/orgs","repos_url":"https://api.github.com/users/Zverik/repos","events_url":"https://api.github.com/users/Zverik/events{/privacy}","received_events_url":"https://api.github.com/users/Zverik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Zverik/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/Zverik/omim","forks_url":"https://api.github.com/repos/Zverik/omim/forks","keys_url":"https://api.github.com/repos/Zverik/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Zverik/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Zverik/omim/teams","hooks_url":"https://api.github.com/repos/Zverik/omim/hooks","issue_events_url":"https://api.github.com/repos/Zverik/omim/issues/events{/number}","events_url":"https://api.github.com/repos/Zverik/omim/events","assignees_url":"https://api.github.com/repos/Zverik/omim/assignees{/user}","branches_url":"https://api.github.com/repos/Zverik/omim/branches{/branch}","tags_url":"https://api.github.com/repos/Zverik/omim/tags","blobs_url":"https://api.github.com/repos/Zverik/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Zverik/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Zverik/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/Zverik/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Zverik/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/Zverik/omim/languages","stargazers_url":"https://api.github.com/repos/Zverik/omim/stargazers","contributors_url":"https://api.github.com/repos/Zverik/omim/contributors","subscribers_url":"https://api.github.com/repos/Zverik/omim/subscribers","subscription_url":"https://api.github.com/repos/Zverik/omim/subscription","commits_url":"https://api.github.com/repos/Zverik/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/Zverik/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/Zverik/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/Zverik/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/Zverik/omim/contents/{+path}","compare_url":"https://api.github.com/repos/Zverik/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Zverik/omim/merges","archive_url":"https://api.github.com/repos/Zverik/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Zverik/omim/downloads","issues_url":"https://api.github.com/repos/Zverik/omim/issues{/number}","pulls_url":"https://api.github.com/repos/Zverik/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/Zverik/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/Zverik/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Zverik/omim/labels{/name}","releases_url":"https://api.github.com/repos/Zverik/omim/releases{/id}","deployments_url":"https://api.github.com/repos/Zverik/omim/deployments","created_at":"2015-09-30T10:43:06Z","updated_at":"2015-09-30T10:45:15Z","pushed_at":"2016-11-29T10:21:37Z","git_url":"git://github.com/Zverik/omim.git","ssh_url":"git@github.com:Zverik/omim.git","clone_url":"https://github.com/Zverik/omim.git","svn_url":"https://github.com/Zverik/omim","homepage":null,"size":2785946,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:master","ref":"master","sha":"23fa9903eb43495a60316f8329edf3a92f0b5f33","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2016-11-29T07:18:07Z","pushed_at":"2016-11-29T11:29:47Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":2913743,"stargazers_count":2051,"watchers_count":2051,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":408,"mirror_url":null,"open_issues_count":369,"forks":408,"open_issues":369,"watchers":2051,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4828"},"html":{"href":"https://github.com/mapsme/omim/pull/4828"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/4828"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/4828/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4828/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4828/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/1b9869ab995171845f1ccf9fe22674ba63aba6aa"}}}}
{"actor":{"display_login":"milchakov"}}