Advertisement
citstudio

Web submitter Helper, Codeigniter

Jun 29th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. /*
  2.   Document   : Web submitter
  3.   Created on : May 7, 2014, 9:12:38 AM
  4.   Author     : Suhendra - citstudio
  5.   Description:
  6.  
  7.  */
  8.  
  9. /*
  10.   CREATE TABLE `mt_updateservices` (
  11.       `id`  int(11) NOT NULL AUTO_INCREMENT ,
  12.       `url`  varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
  13.       `is_active`  enum('1','0') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '1' ,
  14.       PRIMARY KEY (`id`)
  15.   )
  16.   ENGINE=InnoDB
  17.   DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
  18.   AUTO_INCREMENT=1
  19.   ROW_FORMAT=COMPACT;
  20.  
  21.   CREATE TABLE `mt_updateslog` (
  22.       `id`  bigint(20) NOT NULL AUTO_INCREMENT ,
  23.       `update_id`  int(11) NULL DEFAULT NULL ,
  24.       `submit_date`  datetime NULL DEFAULT NULL ,
  25.       `result`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
  26.       `url`  varchar(250) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
  27.       PRIMARY KEY (`id`)
  28.   )
  29.   ENGINE=InnoDB
  30.   DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
  31.   AUTO_INCREMENT=1
  32.   ROW_FORMAT=COMPACT;
  33.  
  34.   $var = submit("Title", "protocols://domain.tld",TRUE / FALSE);
  35.  */
  36.  
  37. function submit($title = "Title", $url = "Slug", $displayResult = FALSE) {
  38.     $ci = &get_instance();
  39.     $result = TRUE;
  40.     $ci->load->library('xmlrpc');
  41.  
  42.     $services = $ci->db->query("SELECT * FROM mt_updateservices")->result_array();
  43.     $check_log = $ci->db->query("SELECT * FROM mt_updateslog WHERE url='" . $url . "'")->result_array();
  44.     if (sizeof($check_log) == 0) {
  45.         foreach ($services as $value) :
  46.             $ci->xmlrpc->server($value, 80);
  47.             $ci->xmlrpc->method('weblogUpdates.ping');
  48.             $request = array($title, $url);
  49.             $ci->xmlrpc->request($request);
  50.             if (!$ci->xmlrpc->send_request()) {
  51.                 if ($displayResult) {
  52.                     $result = $ci->xmlrpc->display_error() . "<br/>";
  53.                 } else {
  54.                     $result = FALSE;
  55.                 }
  56.             } else {
  57.                 $sql = "INSERT INTO mt_updatelog (update_id,submit_date, result, url) VALUES ";
  58.                 $sql .= "('" . $value["id"] . "','" . date("Y-m-d") . "','" . $ci->xmlrpc->display_response() . "','" . $url . "')";
  59.                 $ci->db->query($sql);
  60.                 if ($displayResult) {
  61.                     $result = $ci->xmlrpc->display_response() . "<br/>";
  62.                 } else {
  63.                     $result = FALSE;
  64.                 }
  65.             }
  66.         endforeach;
  67.     } else {
  68.         if ($displayResult) {
  69.             $result = "Calm down boys" . "<br/>";
  70.         } else {
  71.             $result = FALSE;
  72.         }
  73.     }
  74.     return $result;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement