]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3072 from Hypolite/issue/#3062
authorMichael Vogel <icarus@dabo.de>
Sat, 28 Jan 2017 06:32:18 +0000 (07:32 +0100)
committerGitHub <noreply@github.com>
Sat, 28 Jan 2017 06:32:18 +0000 (07:32 +0100)
Using placeholder attribute instead of hacky JS

include/datetime.php
include/dfrn.php
include/event.php

index 779c7a5aadae7f9b46e33fa1525130bbf3abad9b..8d4961cd7c39334776487958711a40e99036ac10 100644 (file)
@@ -571,6 +571,17 @@ function update_contact_birthdays() {
                         *
                         */
 
+                       // Check for duplicates
+                       $s = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+                               intval($rr['uid']),
+                               intval($rr['id']),
+                               dbesc(datetime_convert('UTC','UTC', $nextbd)),
+                               dbesc('birthday'));
+
+                       if (dbm::is_result($s)) {
+                               continue;
+                       }
+
                        $bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
                        $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
 
index ccb43fa98e463d2059059087b2f3b79d75dc9cd7..e9bdaec6649772abaf5b8ebfe7da6666c5c5bd0a 100644 (file)
@@ -1105,12 +1105,22 @@ class dfrn {
         */
        private function birthday_event($contact, $birthday) {
 
+               // Check for duplicates
+               $r = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+                       intval($contact["uid"]),
+                       intval($contact["id"]),
+                       dbesc(datetime_convert("UTC","UTC", $birthday)),
+                       dbesc("birthday"));
+
+               if (dbm::is_result($r)) {
+                       return;
+               }
+
                logger("updating birthday: ".$birthday." for contact ".$contact["id"]);
 
                $bdtext = sprintf(t("%s\'s birthday"), $contact["name"]);
                $bdtext2 = sprintf(t("Happy Birthday %s"), " [url=".$contact["url"]."]".$contact["name"]."[/url]") ;
 
-
                $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
                        VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
                        intval($contact["uid"]),
index 785558beddadb994425be575867243a66a903ac8..9e5bafbdb0837c200b0644edca11b51154ea3b17 100644 (file)
@@ -493,6 +493,26 @@ function get_event_strings() {
        return $i18n;
 }
 
+/// @todo We should replace this with a separate update function if there is some time left
+/**
+ * @brief Removes duplicated birthday events
+ *
+ * @param array $dates Array of possibly duplicated events
+ * @return array Cleaned events
+ */
+function event_remove_duplicates($dates) {
+       $dates2 = array();
+
+       foreach ($dates AS $date) {
+               if ($date['type'] == 'birthday') {
+                       $dates2[$date['uid']."-".$date['cid']."-".$date['start']] = $date;
+               } else {
+                       $dates2[] = $date;
+               }
+       }
+       return $dates2;
+}
+
 /**
  * @brief Get an event by its event ID
  *
@@ -516,9 +536,9 @@ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') {
                intval($event_params["event_id"])
        );
 
-       if (dbm::is_result($r))
-               return $r;
-
+       if (dbm::is_result($r)) {
+               return event_remove_duplicates($r);
+       }
 }
 
 /**
@@ -558,8 +578,9 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
                        dbesc($event_params["adjust_finish"])
        );
 
-       if (dbm::is_result($r))
-               return $r;
+       if (dbm::is_result($r)) {
+               return event_remove_duplicates($r);
+       }
 }
 
 /**
@@ -568,7 +589,7 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
  * @param array $arr Event query array
  * @return array Event array for the template
  */
-function process_events ($arr) {
+function process_events($arr) {
        $events=array();
 
        $last_date = '';