329 | | (progn |
330 | | (if (and twittering-proxy-use twittering-proxy-server) |
331 | | (setq server twittering-proxy-server |
332 | | port (if (integerp twittering-proxy-port) |
333 | | (int-to-string twittering-proxy-port) |
334 | | twittering-proxy-port)) |
335 | | (setq server "twitter.com" |
336 | | port "80")) |
337 | | (setq proc |
338 | | (open-network-stream |
339 | | "network-connection-process" (twittering-http-buffer) |
340 | | server (string-to-number port))) |
341 | | (set-process-sentinel proc sentinel) |
342 | | (process-send-string |
343 | | proc |
344 | | (let ((nl "\r\n") |
345 | | request) |
346 | | (setq request |
347 | | (concat "GET http://twitter.com/" method-class "/" method ".xml HTTP/1.1" nl |
348 | | "Host: twitter.com" nl |
349 | | "User-Agent: " (twittering-user-agent) nl |
350 | | "Authorization: Basic " |
351 | | (base64-encode-string |
352 | | (concat twittering-username ":" (twittering-get-password))) |
353 | | nl |
354 | | "Accept: text/xml" |
355 | | ",application/xml" |
356 | | ",application/xhtml+xml" |
357 | | ",application/html;q=0.9" |
358 | | ",text/plain;q=0.8" |
359 | | ",image/png,*/*;q=0.5" nl |
360 | | "Accept-Charset: utf-8;q=0.7,*;q=0.7" nl |
361 | | (when twittering-proxy-use |
362 | | "Proxy-Connection: Keep-Alive" nl |
363 | | (when (and proxy-user proxy-password) |
364 | | (concat |
365 | | "Proxy-Authorization: Basic " |
366 | | (base64-encode-string |
367 | | (concat proxy-user ":" |
368 | | proxy-password)) |
369 | | nl))) |
370 | | nl nl)) |
371 | | (debug-print (concat "GET Request\n" request)) |
372 | | request))) |
| 332 | (progn |
| 333 | (if (and twittering-proxy-use twittering-proxy-server) |
| 334 | (setq server twittering-proxy-server |
| 335 | port (if (integerp twittering-proxy-port) |
| 336 | (int-to-string twittering-proxy-port) |
| 337 | twittering-proxy-port)) |
| 338 | (setq server "twitter.com" |
| 339 | port "80")) |
| 340 | (setq proc |
| 341 | (open-network-stream |
| 342 | "network-connection-process" (twittering-http-buffer) |
| 343 | server (string-to-number port))) |
| 344 | (set-process-sentinel proc sentinel) |
| 345 | (process-send-string |
| 346 | proc |
| 347 | (let ((nl "\r\n") |
| 348 | request) |
| 349 | (setq request |
| 350 | (concat "GET http://twitter.com/" method-class "/" method ".xml HTTP/1.1" nl |
| 351 | "Host: twitter.com" nl |
| 352 | "User-Agent: " (twittering-user-agent) nl |
| 353 | "Authorization: Basic " |
| 354 | (base64-encode-string |
| 355 | (concat twittering-username ":" (twittering-get-password))) |
| 356 | nl |
| 357 | "Accept: text/xml" |
| 358 | ",application/xml" |
| 359 | ",application/xhtml+xml" |
| 360 | ",application/html;q=0.9" |
| 361 | ",text/plain;q=0.8" |
| 362 | ",image/png,*/*;q=0.5" nl |
| 363 | "Accept-Charset: utf-8;q=0.7,*;q=0.7" nl |
| 364 | (when twittering-proxy-use |
| 365 | "Proxy-Connection: Keep-Alive" nl |
| 366 | (when (and proxy-user proxy-password) |
| 367 | (concat |
| 368 | "Proxy-Authorization: Basic " |
| 369 | (base64-encode-string |
| 370 | (concat proxy-user ":" |
| 371 | proxy-password)) |
| 372 | nl))) |
| 373 | nl nl)) |
| 374 | (debug-print (concat "GET Request\n" request)) |
| 375 | request))) |
417 | | (assocref key status)) |
418 | | (profile-image |
419 | | () |
420 | | (let ((profile-image-url (attr 'user-profile-image-url)) |
421 | | (icon-string "\n ")) |
422 | | (if (string-match "/\\([^/?]+\\)\\(?:\\?\\|$\\)" profile-image-url) |
423 | | (let ((filename (match-string-no-properties 1 profile-image-url))) |
424 | | ;; download icons if does not exist |
425 | | (if (file-exists-p (concat twittering-tmp-dir |
426 | | "/" filename)) |
427 | | t |
428 | | (add-to-list 'twittering-image-stack profile-image-url)) |
429 | | |
430 | | (when (and icon-string twittering-icon-mode) |
431 | | (set-text-properties |
432 | | 1 2 `(display |
433 | | (image :type ,(twittering-image-type filename) |
434 | | :file ,(concat twittering-tmp-dir |
435 | | "/" |
436 | | filename))) |
437 | | icon-string) |
438 | | icon-string) |
439 | | ))))) |
| 420 | (assocref key status)) |
| 421 | (profile-image |
| 422 | () |
| 423 | (let ((profile-image-url (attr 'user-profile-image-url)) |
| 424 | (icon-string "\n ")) |
| 425 | (if (string-match "/\\([^/?]+\\)\\(?:\\?\\|$\\)" profile-image-url) |
| 426 | (let ((filename (match-string-no-properties 1 profile-image-url))) |
| 427 | ;; download icons if does not exist |
| 428 | (if (file-exists-p (concat twittering-tmp-dir |
| 429 | "/" filename)) |
| 430 | t |
| 431 | (add-to-list 'twittering-image-stack profile-image-url)) |
| 432 | |
| 433 | (when (and icon-string twittering-icon-mode) |
| 434 | (set-text-properties |
| 435 | 1 2 `(display |
| 436 | (image :type ,(twittering-image-type filename) |
| 437 | :file ,(concat twittering-tmp-dir |
| 438 | "/" |
| 439 | filename))) |
| 440 | icon-string) |
| 441 | icon-string) |
| 442 | ))))) |
447 | | (setq c (string-to-char (match-string-no-properties 1 format-str))) |
448 | | (if (> found-at cursor) |
449 | | (list-push (substring format-str cursor found-at) result) |
450 | | "|") |
451 | | (setq cursor (match-end 1)) |
452 | | |
453 | | (case c |
454 | | ((?s) ; %s - screen_name |
455 | | (list-push (attr 'user-screen-name) result)) |
456 | | ((?S) ; %S - name |
457 | | (list-push (attr 'user-name) result)) |
458 | | ((?i) ; %i - profile_image |
459 | | (list-push (profile-image) result)) |
460 | | ((?d) ; %d - description |
461 | | (list-push (attr 'user-description) result)) |
462 | | ((?l) ; %l - location |
463 | | (list-push (attr 'user-location) result)) |
464 | | ((?L) ; %L - " [location]" |
465 | | (let ((location (attr 'user-location))) |
466 | | (unless (or (null location) (string= "" location)) |
467 | | (list-push (concat " [" location "]") result)) )) |
468 | | ((?u) ; %u - url |
469 | | (list-push (attr 'user-url) result)) |
470 | | ((?j) ; %j - user.id |
471 | | (list-push (attr 'user-id) result)) |
472 | | ((?p) ; %p - protected? |
473 | | (let ((protected (attr 'user-protected))) |
474 | | (when (string= "true" protected) |
475 | | (list-push "[x]" result)))) |
476 | | ((?c) ; %c - created_at (raw UTC string) |
477 | | (list-push (attr 'created-at) result)) |
478 | | ((?C) ; %C{time-format-str} - created_at (formatted with time-format-str) |
479 | | (list-push (twittering-local-strftime |
480 | | (or (match-string-no-properties 2 format-str) "%H:%M:%S") |
481 | | (attr 'created-at)) |
482 | | result)) |
483 | | ((?@) ; %@ - X seconds ago |
484 | | (let ((created-at |
485 | | (apply |
486 | | 'encode-time |
487 | | (parse-time-string (attr 'created-at)))) |
488 | | (now (current-time))) |
489 | | (let ((secs (+ (* (- (car now) (car created-at)) 65536) |
490 | | (- (cadr now) (cadr created-at))))) |
491 | | (list-push (cond ((< secs 5) "less than 5 seconds ago") |
492 | | ((< secs 10) "less than 10 seconds ago") |
493 | | ((< secs 20) "less than 20 seconds ago") |
494 | | ((< secs 30) "half a minute ago") |
495 | | ((< secs 60) "less than a minute ago") |
496 | | ((< secs 150) "1 minute ago") |
497 | | ((< secs 2400) (format "%d minutes ago" |
498 | | (/ (+ secs 30) 60))) |
499 | | ((< secs 5400) "about 1 hour ago") |
500 | | ((< secs 84600) (format "about %d hours ago" |
501 | | (/ (+ secs 1800) 3600))) |
502 | | (t (format-time-string "%I:%M %p %B %d, %Y" created-at))) |
503 | | result)))) |
504 | | ((?t) ; %t - text |
505 | | (list-push ;(clickable-text) |
506 | | (attr 'text) |
507 | | result)) |
508 | | ((?') ; %' - truncated |
509 | | (let ((truncated (attr 'truncated))) |
510 | | (when (string= "true" truncated) |
511 | | (list-push "..." result)))) |
512 | | ((?f) ; %f - source |
513 | | (list-push (attr 'source) result)) |
514 | | ((?#) ; %# - id |
515 | | (list-push (attr 'id) result)) |
516 | | (t |
517 | | (list-push (char-to-string c) result))) |
518 | | ) |
| 450 | (setq c (string-to-char (match-string-no-properties 1 format-str))) |
| 451 | (if (> found-at cursor) |
| 452 | (list-push (substring format-str cursor found-at) result) |
| 453 | "|") |
| 454 | (setq cursor (match-end 1)) |
| 455 | |
| 456 | (case c |
| 457 | ((?s) ; %s - screen_name |
| 458 | (list-push (attr 'user-screen-name) result)) |
| 459 | ((?S) ; %S - name |
| 460 | (list-push (attr 'user-name) result)) |
| 461 | ((?i) ; %i - profile_image |
| 462 | (list-push (profile-image) result)) |
| 463 | ((?d) ; %d - description |
| 464 | (list-push (attr 'user-description) result)) |
| 465 | ((?l) ; %l - location |
| 466 | (list-push (attr 'user-location) result)) |
| 467 | ((?L) ; %L - " [location]" |
| 468 | (let ((location (attr 'user-location))) |
| 469 | (unless (or (null location) (string= "" location)) |
| 470 | (list-push (concat " [" location "]") result)) )) |
| 471 | ((?u) ; %u - url |
| 472 | (list-push (attr 'user-url) result)) |
| 473 | ((?j) ; %j - user.id |
| 474 | (list-push (attr 'user-id) result)) |
| 475 | ((?p) ; %p - protected? |
| 476 | (let ((protected (attr 'user-protected))) |
| 477 | (when (string= "true" protected) |
| 478 | (list-push "[x]" result)))) |
| 479 | ((?c) ; %c - created_at (raw UTC string) |
| 480 | (list-push (attr 'created-at) result)) |
| 481 | ((?C) ; %C{time-format-str} - created_at (formatted with time-format-str) |
| 482 | (list-push (twittering-local-strftime |
| 483 | (or (match-string-no-properties 2 format-str) "%H:%M:%S") |
| 484 | (attr 'created-at)) |
| 485 | result)) |
| 486 | ((?@) ; %@ - X seconds ago |
| 487 | (let ((created-at |
| 488 | (apply |
| 489 | 'encode-time |
| 490 | (parse-time-string (attr 'created-at)))) |
| 491 | (now (current-time))) |
| 492 | (let ((secs (+ (* (- (car now) (car created-at)) 65536) |
| 493 | (- (cadr now) (cadr created-at))))) |
| 494 | (list-push (cond ((< secs 5) "less than 5 seconds ago") |
| 495 | ((< secs 10) "less than 10 seconds ago") |
| 496 | ((< secs 20) "less than 20 seconds ago") |
| 497 | ((< secs 30) "half a minute ago") |
| 498 | ((< secs 60) "less than a minute ago") |
| 499 | ((< secs 150) "1 minute ago") |
| 500 | ((< secs 2400) (format "%d minutes ago" |
| 501 | (/ (+ secs 30) 60))) |
| 502 | ((< secs 5400) "about 1 hour ago") |
| 503 | ((< secs 84600) (format "about %d hours ago" |
| 504 | (/ (+ secs 1800) 3600))) |
| 505 | (t (format-time-string "%I:%M %p %B %d, %Y" created-at))) |
| 506 | result)))) |
| 507 | ((?t) ; %t - text |
| 508 | (list-push ;(clickable-text) |
| 509 | (attr 'text) |
| 510 | result)) |
| 511 | ((?') ; %' - truncated |
| 512 | (let ((truncated (attr 'truncated))) |
| 513 | (when (string= "true" truncated) |
| 514 | (list-push "..." result)))) |
| 515 | ((?f) ; %f - source |
| 516 | (list-push (attr 'source) result)) |
| 517 | ((?#) ; %# - id |
| 518 | (list-push (attr 'id) result)) |
| 519 | (t |
| 520 | (list-push (char-to-string c) result))) |
| 521 | ) |
556 | | request) |
557 | | (setq request |
558 | | (concat "POST http://twitter.com/" method-class "/" method ".xml?" |
559 | | (if parameters |
560 | | (mapconcat |
561 | | (lambda (param-pair) |
562 | | (format "%s=%s" |
563 | | (twittering-percent-encode (car param-pair)) |
564 | | (twittering-percent-encode (cdr param-pair)))) |
565 | | parameters |
566 | | "&")) |
567 | | " HTTP/1.1" nl |
568 | | "Host: twitter.com" nl |
569 | | "User-Agent: " (twittering-user-agent) nl |
570 | | "Authorization: Basic " |
571 | | (base64-encode-string |
572 | | (concat twittering-username ":" (twittering-get-password))) |
573 | | nl |
574 | | "Content-Type: text/plain" nl |
575 | | "Content-Length: 0" nl |
576 | | (when twittering-proxy-use |
577 | | "Proxy-Connection: Keep-Alive" nl |
578 | | (when (and proxy-user proxy-password) |
579 | | (concat |
580 | | "Proxy-Authorization: Basic " |
581 | | (base64-encode-string |
582 | | (concat proxy-user ":" |
583 | | proxy-password)) |
584 | | nl))) |
585 | | nl nl)) |
586 | | (debug-print (concat "POST Request\n" request)) |
587 | | request))))) |
| 559 | request) |
| 560 | (setq request |
| 561 | (concat "POST http://twitter.com/" method-class "/" method ".xml?" |
| 562 | (if parameters |
| 563 | (mapconcat |
| 564 | (lambda (param-pair) |
| 565 | (format "%s=%s" |
| 566 | (twittering-percent-encode (car param-pair)) |
| 567 | (twittering-percent-encode (cdr param-pair)))) |
| 568 | parameters |
| 569 | "&")) |
| 570 | " HTTP/1.1" nl |
| 571 | "Host: twitter.com" nl |
| 572 | "User-Agent: " (twittering-user-agent) nl |
| 573 | "Authorization: Basic " |
| 574 | (base64-encode-string |
| 575 | (concat twittering-username ":" (twittering-get-password))) |
| 576 | nl |
| 577 | "Content-Type: text/plain" nl |
| 578 | "Content-Length: 0" nl |
| 579 | (when twittering-proxy-use |
| 580 | "Proxy-Connection: Keep-Alive" nl |
| 581 | (when (and proxy-user proxy-password) |
| 582 | (concat |
| 583 | "Proxy-Authorization: Basic " |
| 584 | (base64-encode-string |
| 585 | (concat proxy-user ":" |
| 586 | proxy-password)) |
| 587 | nl))) |
| 588 | nl nl)) |
| 589 | (debug-print (concat "POST Request\n" request)) |
| 590 | request))))) |
790 | | (found-at nil) |
791 | | (result '())) |
792 | | (while (setq found-at |
793 | | (string-match "&\\(#\\([0-9]+\\)\\|\\([A-Za-z]+\\)\\);" |
794 | | encoded-str cursor)) |
795 | | (when (> found-at cursor) |
796 | | (list-push (substring encoded-str cursor found-at) result)) |
797 | | (let ((number-entity (match-string-no-properties 2 encoded-str)) |
798 | | (letter-entity (match-string-no-properties 3 encoded-str))) |
799 | | (cond (number-entity |
800 | | (list-push |
801 | | (char-to-string |
802 | | (twittering-ucs-to-char |
803 | | (string-to-number number-entity))) result)) |
804 | | (letter-entity |
805 | | (cond ((string= "gt" letter-entity) (list-push ">" result)) |
806 | | ((string= "lt" letter-entity) (list-push "<" result)) |
807 | | (t (list-push "?" result)))) |
808 | | (t (list-push "?" result))) |
809 | | (setq cursor (match-end 0)))) |
810 | | (list-push (substring encoded-str cursor) result) |
811 | | (apply 'concat (nreverse result))) |
| 793 | (found-at nil) |
| 794 | (result '())) |
| 795 | (while (setq found-at |
| 796 | (string-match "&\\(#\\([0-9]+\\)\\|\\([A-Za-z]+\\)\\);" |
| 797 | encoded-str cursor)) |
| 798 | (when (> found-at cursor) |
| 799 | (list-push (substring encoded-str cursor found-at) result)) |
| 800 | (let ((number-entity (match-string-no-properties 2 encoded-str)) |
| 801 | (letter-entity (match-string-no-properties 3 encoded-str))) |
| 802 | (cond (number-entity |
| 803 | (list-push |
| 804 | (char-to-string |
| 805 | (twittering-ucs-to-char |
| 806 | (string-to-number number-entity))) result)) |
| 807 | (letter-entity |
| 808 | (cond ((string= "gt" letter-entity) (list-push ">" result)) |
| 809 | ((string= "lt" letter-entity) (list-push "<" result)) |
| 810 | (t (list-push "?" result)))) |
| 811 | (t (list-push "?" result))) |
| 812 | (setq cursor (match-end 0)))) |
| 813 | (list-push (substring encoded-str cursor) result) |
| 814 | (apply 'concat (nreverse result))) |