Esempio n. 1
0
 /**
  * 从字符串中抓取远程图片
  *
  * @author tuzwu
  * @createtime
  * @modifytime
  * @param	
  * @return string 替换后的字符串
  */
 public function save_remote($str = '', $watermark_enable = false)
 {
     if (empty($str)) {
         return false;
     }
     $list = $replace_array = array();
     //这里存放结果map
     $c1 = preg_match_all('/<img\\s.*?>/', $str, $m1);
     //先取出所有img标签文本
     for ($i = 0; $i < $c1; $i++) {
         $c2 = preg_match_all('/(\\w+)\\s*=\\s*(?:(?:(["\'])(.*?)(?=\\2))|([^\\/\\s]*))/', $m1[0][$i], $m2);
         //匹配所有属性
         for ($j = 0; $j < $c2; $j++) {
             $img_attr = $m2[1][$j];
             if (!in_array($img_attr, array('src', 'alt', 'title'))) {
                 continue;
             }
             $list[$i][$img_attr] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];
         }
     }
     foreach ($list as $k => $v) {
         if (strpos($v['src'], '://') === false || strpos_array($v['src'], array('127.0.0.1', 'localhost', ATTACHMENT_URL)) !== false) {
             continue;
         }
         $alt = isset($v['alt']) ? remove_xss($v['alt']) : remove_xss($v['title']);
         $new_path = $this->get_remote_file($v['src'], array('alt' => $alt));
         if ($new_path) {
             $replace_array['old'][] = $v['src'];
             $replace_array['new'][] = $new_path;
         }
     }
     return empty($replace_array['new']) ? $str : str_ireplace($replace_array['old'], $replace_array['new'], $str);
 }
 public function strposArray($haystack, $needles)
 {
     if (is_array($needles)) {
         foreach ($needles as $str) {
             if (is_array($str)) {
                 $pos = strpos_array($haystack, $str);
             } else {
                 $pos = strpos($haystack, $str);
             }
             if ($pos !== false) {
                 return $pos;
             }
         }
     } else {
         return strpos($haystack, $needles);
     }
 }
Esempio n. 3
0
function strpos_array($haystack, $needles)
{
    if (is_array($needles)) {
        foreach ($needles as $str) {
            if (is_array($str)) {
                $pos = strpos_array($haystack, $str);
            } else {
                if ($str != "") {
                    // Check if needle is not empty (added by JvdH 20141219)
                    $pos = strpos($haystack, $str);
                }
            }
            if ($pos !== FALSE) {
                return $pos;
            }
        }
    } else {
        return strpos($haystack, $needles);
    }
}
Esempio n. 4
0
 private function _verifySignup($dummyEmail)
 {
     // Hardcoded sign-up page to search
     $url = 'http://underconstructiontemplate.com/';
     $this->load->model('home_verify');
     // Prevent request flooding by checking if URL was previously verified
     if ($this->home_verify->status($url) == "on-file") {
         $data['result'] = "Entry Already On-File";
         $this->load->view('home_index', $data);
     } else {
         // Load DOM
         $doc = new DOMDocument();
         @$doc->loadHTMLFile($url);
         $xpath = new DOMXpath($doc);
         // Get DOMNodeList of <input> fields within each form
         $get_FormInputs = $xpath->query('//form/input');
         // Turn the <input> DOMNodeList into a workable array
         $FormInputs = array();
         foreach ($get_FormInputs as $FormInput) {
             $FormInputs[] = array('id' => $FormInput->getAttribute('id'), 'name' => $FormInput->getAttribute('name'), 'value' => $FormInput->getAttribute('value'), 'max-length' => $FormInput->getAttribute('max-length') ? $FormInput->getAttribute('max-length') : 'false', 'type' => $FormInput->getAttribute('type'), 'is_verified' => 'false');
         }
         /*
          * Custom 'strpos' or string position implementation.
          * Allows the program to search through an array of needles
          * to find first <input> value condition that indicates an e-mail requirement
          */
         function strpos_array($haystack, $needle)
         {
             // Check and set the $needle to an array if need be.
             if (!is_array($needle)) {
                 $needle = array($needle);
             }
             foreach ($needle as $query) {
                 if ($position = strpos($haystack, $query) != false) {
                     return true;
                 }
             }
             return false;
         }
         // Array of <input> value conditions
         $InputConditions = array('@', 'at', 'mail', 'e-mail');
         // Verify whether or not an input is for an e-mail
         $i = 0;
         while ($i < count($FormInputs)) {
             if ($FormInputs[$i]['type'] == 'email') {
                 $FormInputs[$i]['is_verified'] = 'true';
             }
             if ($FormInputs[$i]['max-length'] == '254') {
                 $FormInputs[$i]['is_verified'] = 'true';
             }
             if ($FormInputs[$i]['type'] == 'text') {
                 if (strpos_array($FormInputs[$i]['value'], $InputConditions) == true) {
                     $FormInputs[$i]['is_verified'] = 'true';
                     $i++;
                 } else {
                     $FormInputs[$i]['is_verified'] = 'false';
                     $i++;
                 }
             }
             $i++;
         }
         /**
          *  Create a Query for the E-Mail Sign-up Form
          *
          *  Note: This could be expanded to account for all 24 input element types,
          *        but to keep things easy I stopped at what the specified page required.
          */
         $form_fields = array();
         for ($i2 = 0; $i2 < count($FormInputs); $i2++) {
             if ($FormInputs[$i2]['is_verified'] == 'true') {
                 $form_fields += array($FormInputs[$i2]['name'] => $dummyEmail);
             }
         }
         // Get <form> action path
         $get_FormAction = $xpath->query('//form/@action');
         // Open cURL connection
         $FormAction = $get_FormAction->item(0)->nodeValue . '/';
         $fields = " ";
         // Make the data URL compliant for POST
         foreach ($form_fields as $key => $value) {
             $fields .= $key . '=' . $value . '&';
         }
         rtrim($fields, '&');
         // Open cURL connection
         $curl = curl_init();
         // Set URL, POST vars, and data
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($curl, CURLOPT_URL, $FormAction);
         curl_setopt($curl, CURLOPT_POST, count($form_fields));
         curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
         curl_setopt($curl, CURLOPT_REFERER, $FormAction);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
         // Request POST result page
         $curl_result = curl_exec($curl);
         // Close cURL connection
         curl_close($curl);
         // Load DOM for POST results
         $output = new DOMDocument();
         libxml_use_internal_errors(true);
         $output->loadHTML($curl_result);
         $xpath2 = new DOMXpath($output);
         // Check for confirmation validation error/message container's class
         $get_UserEmailErrors = $xpath2->query('//*[@class="userEmailError"]');
         // Turn 'userEmailError' DOMNodeList into usable array
         $userEmailErrors = array();
         foreach ($get_UserEmailErrors as $EmailErrors) {
             $userEmailErrors[] = array('value' => $EmailErrors->nodeValue);
         }
         // Verify presence of sign-up success confirmation
         if (isset($userEmailErrors[0]) == true && $userEmailErrors[0]['value'] == "Your download link has been sent!") {
             // Success
             $is_verified = true;
             $this->home_verify->verify($url, $is_verified);
         } else {
             // Failure
             $is_verified = false;
             $this->home_verify->verify($url, $is_verified);
         }
     }
 }
Esempio n. 5
0
 private function strpos_array($haystack, $needles)
 {
     if (is_array($needles)) {
         foreach ($needles as $str) {
             if (is_array($str)) {
                 $pos = strpos_array($haystack, $str);
             } else {
                 $pos = strpos($haystack, $str);
             }
             if ($pos !== FALSE) {
                 return TRUE;
             }
         }
     } else {
         return strpos($haystack, $needles);
     }
 }