]> git.mxchange.org Git - friendica.git/commitdiff
set frequency of poll per contact, other misc fixes (photo now has contact-id)
authorMike Macgirvin <mike@macgirvin.com>
Sun, 1 Aug 2010 12:46:51 +0000 (05:46 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Sun, 1 Aug 2010 12:46:51 +0000 (05:46 -0700)
database.sql
include/poller.php
mod/contacts.php
mod/dfrn_confirm.php
view/contact_edit.tpl
view/contact_selectors.php
view/style.css

index cfe0df9d22cbe984785b147b837dc62d7f9ced4f..6b8b1281b35f26cff31e7c112475a3f9587fe53f 100644 (file)
@@ -204,6 +204,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
 CREATE TABLE IF NOT EXISTS `photo` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `uid` int(10) unsigned NOT NULL,
+  `contact-id` int(10) unsigned NOT NULL,
   `resource-id` char(255) NOT NULL,
   `created` datetime NOT NULL,
   `edited` datetime NOT NULL,
index dad50ab9a35ec13727aaf103d5ccf18d055208da..e0b4d79b21aac18e4f970c7f75d8cd9190da6d33 100644 (file)
@@ -17,7 +17,7 @@ require_once('include/items.php');
 
 if($argc < 2)
        exit;
-
+dbg(3);
        $a->set_baseurl($argv[1]);
 
        $contacts = q("SELECT * FROM `contact` WHERE `dfrn-id` != '' AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
@@ -27,6 +27,39 @@ if($argc < 2)
 
        foreach($contacts as $contact) {
 
+               if($contact['priority']) {
+
+                       $update = false;
+                       $t = $contact['last-update'];
+
+                       switch ($contact['priority']) {
+                               case 5:
+                                       if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', t . " + 1 month"))
+                                               $update = true;
+                                       break;                                  
+                               case 4:
+                                       if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', t . " + 1 week"))
+                                               $update = true;
+                                       break;
+                               case 3:
+                                       if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', t . " + 1 day"))
+                                               $update = true;
+                                       break;
+                               case 2:
+                                       if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', t . " + 12 hour"))
+                                               $update = true;
+                                       break;
+                               case 1:
+                               default:
+                                       if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', t . " + 1 hour"))
+                                               $update = true;
+                                       break;
+                       }
+                       if(! $update)
+                               continue;
+               }
+
+
                $importer_uid = $contact['uid'];
 
                $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
@@ -44,7 +77,8 @@ if($argc < 2)
                $url = $contact['poll'] . '?dfrn_id=' . $contact['dfrn-id'] . '&type=data&last_update=' . $last_update ;
 
                $xml = fetch_url($url);
-
+echo "URL: " . $url;
+echo "XML: " . $xml;
                if(! $xml)
                        continue;
 
@@ -61,12 +95,19 @@ if($argc < 2)
                openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
 
                $xml = post_url($contact['poll'],$postvars);
-               if(! strlen($xml))
-                       continue;
 
 echo "XML response:" . $xml . "\r\n";
 echo "Length:" . strlen($xml) . "\r\n";
 
+               if(! strlen($xml)) {
+                       // an empty response may mean there's nothing new - record the fact that we checked
+                       $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
+                               dbesc(datetime_convert()),
+                               intval($contact['id'])
+                       );
+                       continue;
+               }
+
                $feed = new SimplePie();
                $feed->set_raw_data($xml);
                $feed->enable_order_by_date(false);
index 1e3cb8f063b293190bd991443aef211c0a4b0f73..c1b3781bf6376f88a4992a0f4262b5217176798c 100644 (file)
@@ -40,15 +40,20 @@ function contacts_post(&$a) {
                        return;
                }
        }
+       $priority = intval($_POST['priority']);
+       if($priority > 5 || $priority < 0)
+               $priority = 0;
+
        $rating = intval($_POST['reputation']);
        if($rating > 5 || $rating < 0)
                $rating = 0;
 
        $reason = notags(trim($_POST['reason']));
 
-       $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
+       $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
                WHERE `id` = %d AND `uid` = %d LIMIT 1",
                intval($profile_id),
+               intval($priority),
                intval($rating),
                dbesc($reason),
                intval($contact_id),
@@ -91,12 +96,6 @@ function contacts_content(&$a) {
                }
 
 
-//             $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
-//             $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
-//                             dbesc($photo),
-//                             intval($_SESSION['uid'])
-//             );
-       
                if($cmd == 'block') {
                        $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
                        $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -130,19 +129,18 @@ function contacts_content(&$a) {
                if($cmd == 'drop') {
                        $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                intval($contact_id),
-                               intval($_SESSION['uid']));
-
-//                     if(count($photos)) {
-//                             foreach($photos as $p) {
-//                                     q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
-//                                             $p['id']);
-//                             }
-//                     }
-
-                       if(intval($contact_id))
-                               q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
-                                       intval($contact_id)
-                               );
+                               intval($_SESSION['uid'])
+                       );
+
+                       q("DELETE FROM `item` WHERE `contact-id` = %d AND `uid` = %d ",
+                                       intval($contact_id),
+                                       intval($_SESSION['uid'])
+                       );
+                       q("DELETE FROM `photo` WHERE `contact-id` = %d AND `uid` = %d ",
+                                       intval($contact_id),
+                                       intval($_SESSION['uid'])
+                       );
        
                        notice("Contact has been removed." . EOL );
                        goaway($a->get_baseurl() . '/contacts');
@@ -186,6 +184,10 @@ function contacts_content(&$a) {
                }
 
                $o .= replace_macros($tpl,array(
+                       '$poll_interval' => contact_poll_interval($r[0]['priority']),
+                       '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00') 
+                               ? t('Never') 
+                               : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, G:i A')),
                        '$profile_select' => contact_profile_assign($r[0]['profile-id']),
                        '$contact_id' => $r[0]['id'],
                        '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
index ca6afca8bd5a0a3578559f367c8c9f7a40bdfc0d..0298e76a52612f5e3ce5144ddbbadf9587eb6861 100644 (file)
@@ -91,10 +91,11 @@ function dfrn_confirm_post(&$a) {
                                        
                                        $hash = hash('md5',uniqid(mt_rand(),true));
 
-                                       $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
+                                       $r = q("INSERT INTO `photo` ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`,
                                                `height`, `width`, `data`, `scale` )
-                                               VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 4 )",
+                                               VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 4 )",
                                                intval($local_uid),
+                                               intval($dfrn_record),
                                                dbesc($hash),
                                                datetime_convert(),
                                                datetime_convert(),
@@ -107,10 +108,11 @@ function dfrn_confirm_post(&$a) {
                                                $photo_failure = true;
                                        
                                        $img->scaleImage(80);
-                                       $r =  q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
+                                       $r =  q("INSERT INTO `photo` ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`,
                                                 `height`, `width`, `data`, `scale` )
-                                                VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 5 )",
+                                                VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 5 )",
                                                 intval($local_uid),
+                                               intval($dfrn_record),
                                                 dbesc($hash),
                                                 datetime_convert(),
                                                 datetime_convert(),
index 6f1dbbc7c0a3502bd74ffaa8515d97ba6e1d9821..a049c232fe272cb79b00fc903b7ae6acda92494b 100644 (file)
                        <a href="contacts/$contact_id/drop" id="contact-edit-drop-link" onclick="return confirmDelete();" ><img src="images/b_drophide.gif" alt="Delete contact" title="Delete contact" onmouseover="imgbright(this);" onmouseout="imgdull(this);" /></a>
                </div>
                <div id="contact-edit-nav-end"></div>
+               <div id="contact-edit-poll-wrapper">
+                       <div id="contact-edit-last-update-text">Last updated: <span id="contact-edit-last-updated">$last_update</span</div>
+                       <div id="contact-edit-poll-text">Update public posts: </div>
+                       $poll_interval
+               </div>
        </div>
        <div id="contact-edit-end" ></div>
 
index a6cafe4ee93bcbf5462a48e63c6aa3b33cc67075..7c7abfc7c89dde5cbabb8542c309fafd33648937 100644 (file)
@@ -26,12 +26,12 @@ function contact_reputation($current) {
        $o .= "<select id=\"contact-reputation-selector\" name=\"reputation\" />\r\n";
 
        $rep = array(
-               0 => "Unknown | Not categorised",
-               1 => "Block immediately",
-               2 => "Shady, spammer, self-marketer",
-               3 => "Known to me, but no opinion",
-               4 => "OK, probably harmless",
-               5 => "Reputable, has my trust"
+               0 => t('Unknown | Not categorised'),
+               1 => t('Block immediately'),
+               2 => t('Shady, spammer, self-marketer'),
+               3 => t('Known to me, but no opinion'),
+               4 => t('OK, probably harmless'),
+               5 => t('Reputable, has my trust')
        );
 
        foreach($rep as $k => $v) {
@@ -43,4 +43,24 @@ function contact_reputation($current) {
 }
 
 
+function contact_poll_interval($current) {
 
+       $o = '';
+       $o .= '<select id="contact-poll-interval" name="poll" />' . "\r\n";
+
+       $rep = array(
+               0 => t('Frequently'),
+               1 => t('Hourly'),
+               2 => t('Twice daily'),
+               3 => t('Daily'),
+               4 => t('Weekly'),
+               5 => t('Monthly')
+       );
+
+       foreach($rep as $k => $v) {
+               $selected = (($k == $current) ? " selected=\"selected\" " : "");
+               $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
+       }
+       $o .= "</select>\r\n";
+       return $o;
+}
index 0d3b6b29d0cb55b43210eec23b6d803c9f099e85..c7b46a83078ef7fdca302d6b36a593bf09ad9da3 100644 (file)
@@ -16,7 +16,7 @@ body {
        background: #FEFEFE;
        color: #444444;
        font-family: "Lucida Grande", Tahoma, sans-serif;
-       letter-spacing: 1px;
+/*     letter-spacing: 1px; */
 /*     font-family: verdana, sans-serif; */
        font-size: 90%;
        margin-left: 10px;
@@ -880,6 +880,14 @@ input#dfrn-url {
        margin-left: 30px;
 }
 
+#contact-edit-poll-wrapper {
+       margin-left: 50px;
+       margin-top: 30px;
+}
+#contact-edit-poll-text {
+       margin-bottom: 10px;
+}
+
 #contact-edit-photo-wrapper {
        margin-bottom: 20px;
 }