ما الخطأ في هذا البرنامج النصي لمستورد جهات اتصال Gmail لـ Drupal؟

StackOverflow https://stackoverflow.com/questions/827343

سؤال

يحتوي Drupal على وحدة استيراد جهات اتصال Gmail التي كانت قريبة جدًا من العمل منذ حوالي 7 أشهر حتى الآن.ليس لدي القطع اللازمة لتصحيح المشكلة، اختفى المشرف، وأعتقد أن هذا جزء مهم للعمل.لذلك أتوجه إلى StackOverflow للحصول على المساعدة.

المشكلة:عندما تقوم بملء بيانات الاعتماد الخاصة بك وتطلب من البرنامج النصي إعادة جهات الاتصال الخاصة بك، فإنه يقوم بشكل افتراضي بسحب 25.هذا يعمل بشكل جيد.

عندما تطلب منه البحث عن المزيد من جهات الاتصال عن طريق تغيير عنوان URL الذي تستعلم عنه من هذا:

http://www.google.com/m8/feeds/contacts/default/thin  

الى هذا:

http://www.google.com/m8/feeds/contacts/default/thin?max-results=1000

لقد حصلت على الخطأ الفادح التالي:

خطأ فادح:استدعاء وظيفة العضو getAttribute() على غير كائن في path/to/site/sites/all/modules/dcl_importer/scripts/importGData.class.php على الخط 97

وهنا البرنامج النصي:

class GDataMailer {
    static $url_ClientLogin = 'https://www.google.com/accounts/ClientLogin';
    static $url_Feed = 'http://www.google.com/m8/feeds/contacts/default/thin?max-results=65535';

    function newCurlSession($URL, $auth = null) {
        $curl = curl_init();

        $opts = array(
            CURLOPT_URL => $URL,
            CURLOPT_REFERER => '',
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
        );
        if (null != $auth) {
            $opts[CURLOPT_HTTPHEADER] = array(
               'Authorization: GoogleLogin auth='.$auth,
            );
        }
        curl_setopt_array($curl, $opts);
        return $curl;
    }

    function useCurlForPost($curl, $params) {
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        return $curl;
    }

    function getAuthToken($login, $password) {
        $curl = $this->useCurlForPost($this->newCurlSession(self::$url_ClientLogin), array(
           'accountType' => 'HOSTED_OR_GOOGLE',
           'Email' => $login,
           'Passwd' => $password,
           'service' => 'cp',
           'source' => 'Drupal-Contact-Importer',
        ));
        $resp = curl_exec($curl);

        // Look for the important stuff:
        preg_match_all('/Auth=([^\s]*)/si', $resp, $matches);
        if (isset($matches[1][0])) {
            return $matches[1][0];
        } else {
           return false;
        }
    }

    function getAddressbook($login, $password) {
        // check if username and password was given:
        if ((isset($login) && trim($login)=="") || (isset($password) && trim($password)==""))
        {
            $args = func_get_args();
            drupal_set_message('Incorrect login information given: '.print_r($args, true), 'error');
            return false;
        }

        // Get the GData auth token:
        $auth = $this->getAuthToken($login, $password);
        if (false === $auth) {
            drupal_set_message('Login failed', 'error');
            return false;
        }        

        $curl = $this->newCurlSession(self::$url_Feed, $auth);
        $data = curl_exec($curl);

        $doc = new DOMDocument();
        $doc->loadXML($data);
        $path = new DOMXPath($doc);
        $path->registerNamespace('a', 'http://www.w3.org/2005/Atom');
        $path->registerNamespace('gd', 'http://schemas.google.com/g/2005');
        $nodes = $path->query('//a:entry');
        $num = $nodes->length;

        $contacts = array();
        for ($x = 0; $x < $num; $x++) {
            $entry = $nodes->item($x);
            $tnodes = $path->query('a:title', $entry);
            $nnode = $tnodes->item(0);
            $name = $nnode->textContent;
            $enodes = $path->query('gd:email', $entry);
            $mnode = $enodes->item(0);
            $email = $mnode->getAttribute('address');
            // NOTE: Keep in mind that $mnode->getAttribute('rel') tells you what kind of email it is.
            // NOTE: Also remember that there can be multiple emails per entry!
            if (empty($name)) {
                $contacts[] = $email;
            } else {
                $contacts[$name] = $email;
            }
        }        

        return $contacts;
    }
}

السطر 97 هو ذلك $email = $mnode->getAttribute('address'); الخط بالقرب من النهاية.

ما الذي يمكنني تغييره هنا حتى لا أتعرض لهذا الخطأ بعد الآن وأجعله يعمل لصالح مجتمع دروبال؟أريد سحب كل قائمة جهات الاتصال الخاصة بالشخص، وليس 25 فقط.أعتقد أنه إذا أرسلت الرقم عاليًا بدرجة كافية، فسيكون قريبًا بما يكفي لتجاوزه.

هل كانت مفيدة؟

المحلول

بدون اختباره مباشرة، سأحاول استبدال الأسطر 96 - 104 بما يلي:

$mnode = $enodes->item(0);
if (isset($mnode) && is_object($mnode)) {
    $email = $mnode->getAttribute('address');
    // NOTE: Keep in mind that $mnode->getAttribute('rel') tells you what kind of email it is.
    // NOTE: Also remember that there can be multiple emails per entry!
    if (!empty($email)) {
        if (empty($name)) {
            $contacts[] = $email;
        } else {
            $contacts[$name] = $email;
        }
    }
}

gd:email هو عنصر اختياري وفقًا لـ واجهة برمجة تطبيقات بيانات جوجل.إنه اختياري في تنفيذ Gmail أيضًا.تفترض الوحدة التي تستخدمها أنها موجودة وتفشل عندما لا تكون موجودة.

تظل عناوين البريد الإلكتروني المتعددة لكل جهة اتصال دون معالجة، وفقًا للملاحظة:تعليق.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top