function linkHelper($item) { global $app; $item->mood = parseLinks($item->mood); $item->status = parseLinks($item->status); @$app->site->links->add($item); return $item; }
/** * @param $url * Функция для парсинга ссылок */ function parseLinks($url) { global $domain; //имя домена global $recursiveDeep; // глубина рекурсии global $protocol; //протокол global $link_array; // массив с спарсенными ссылками if (strlen($url) <= 1) { return; } if ($recursiveDeep == 0) { //если глубина рекурсии равна 0 $res = parse_url($url); if ($res != false) { $domain = $res['host']; $protocol = $res['scheme']; } else { return; } } $recursiveDeep++; // увеличиваем счетчик глубины рекурсии $doc = new DOMDocument(); $doc->loadHTML(file_get_contents($url)); $elements = $doc->getElementsByTagName('a'); foreach ($elements as $element) { if (count($link_array) > 300) { return; } // устанавливаем лимит на кол-во ссылок $link = $element->getAttribute('href'); if ($link[0] == '/' || $link[0] == '?') { $link = $protocol . "://" . $domain . $link; } $p_link = parse_url($link); if ($p_link == false) { continue; } if ($p_link["host"] != $domain) { continue; } // проверяем ведет ли эта ссылка на внешний сайт if (!link_exists($link) && strlen($link) > 1) { $link_array[] = $link; if ($recursiveDeep < 5) { // проверяем глубину рекурсии parseLinks($link); } } } $recursiveDeep--; // уменьшаем счетчик глубины рекурсии }
$qry_string = substr($phpinclude, $pos_incl + 1); $phpinclude = substr($phpinclude, 0, $pos_incl); $arr_qstr = explode('&', $qry_string); foreach ($arr_qstr as $param_value) { list($qstr_name, $qstr_value) = explode('=', $param_value); ${$qstr_name} = $qstr_value; $_GET[$qstr_name] = $qstr_value; } } if (file_exists($phpinclude)) { include $phpinclude; } else { ?> <script type="text/javascript">setTimeout(function(){showError(404);},100);</script><?php } echo parseLinks(ob_get_clean()); ?> </div> </div> <script type="text/javascript"> var oldC=I("_comments_"); if(oldC)oldC.id="article_comments"; var c=I("article_comments"); if(c)createCommentsForm('<?php echo $_GET["p"]; ?> ',c); var s=I("_share_"); if(s){ url=document.location.href; s.innerHTML="";
/** * Function checkForParsing * * * @param $convoArr * @return mixed */ function checkForParsing($convoArr) { $message = $convoArr['send_to_user']; $oldMsg = $message; $fAr = array("~\\[b\\]~", "~\\[i\\]~", "~\\[u\\]~", "~\\[s\\]~"); $message = parseEmotes($message); $message = strpos($message, "[url") !== false ? parseURLs($message) : $message; $message = strpos($message, "[link") !== false ? parseLinks($message) : $message; $message = strpos($message, "[img]") !== false ? parseImages($message) : $message; $message = parseColors($message); $message = parseFormatting($message); if ($message != $oldMsg) { $convoArr['send_to_user'] = $message; } return $convoArr; }
function shout($nickname, $message) { global $dirs, $paths, $prefs; ensureExists($dirs['logs']); // Ensure the log directory exists $timestamp = microtime_float(); $nickname = substr($nickname, 0, 25); $message = substr($message, 0, 175); $nickname = formatString($nickname); $message = formatString($message); $nickname = cursesGetAway($nickname); $message = cursesGetAway($message); $message = parseLinks($message); $shouttype = (isAdmin()? 'admin' : 'user'); $ip = getIP(); $time = date('h:i a'); $date = date('F j'); $shout = array( 'timestamp' => $timestamp, 'nickname' => $nickname, 'message' => $message, 'ipaddress' => $ip, 'time' => $time, 'date' => $date, 'showuserinfo' => true, 'shouttype' => $shouttype ); $jData = decode($paths['log']); if ($jData == null) $jData = array(); $jData[] = $shout; writeHistory($shout); truncate($jData); $jData = array_values($jData); $output = encode($jData); write($paths['log'], $output, 0773); }
function fetchEnrollments($course_id = False) { if (!$course_id) { return array(); } # Build the API endpoint for fetching the list of students $enrollment_params = array("page=1", 'per_page=50'); $enrollment_params_string = implode('&', $enrollment_params); $enrollments_endpoint = sprintf(BASE_URL, sprintf('/courses/%d/enrollments?%s', $course_id, $enrollment_params_string)); # Initiate cURL, adding the REQUEST_HEADERS to it for authentication $ch = curlhandler($enrollments_endpoint, true); # Execute the request # Fetch the response, $enrollment_list = curl_exec($ch); if (!$enrollment_list) { print 'error fetching student list'; } else { # Strip extra whitespace from the beginning and end then parse response into JSON list($header_string, $enrollment_list) = explode("\r\n\r\n", $enrollment_list, 2); $enrollment_list = trim($enrollment_list); $enrollment_list_2 = json_decode($enrollment_list, true); #print_r($enrollment_list_2); } $headers = parseHeaders($header_string); $links = parseLinks($headers['Link']); if ($links == false) { $enrollment_results = $enrollment_list_2; } else { //print_r($links); $curl_handlers = array(); $mh = curl_multi_init(); for ($x = 0; $x < (int) $links['num_pages']; $x++) { # Initiate cURL, adding the REQUEST_HEADERS to it for authentication $enrollment_params = array("page={$x}", 'per_page=' . $links['per_page']); $enrollment_params_string = implode('&', $enrollment_params); // Set url $rep_enrollments_endpoint = sprintf(BASE_URL, sprintf('/courses/%d/enrollments?%s', $course_id, $enrollment_params_string)); $curl_handlers[$x] = curlHandler($rep_enrollments_endpoint); curl_multi_add_handle($mh, $curl_handlers[$x]); } do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } $enrollment_results = array(); for ($i = 0; $i < (int) $links['num_pages']; $i++) { $content = curl_multi_getcontent($curl_handlers[$i]); $json_response = json_decode($content, true); if ($json_response) { $enrollment_results = array_merge($enrollment_results, $json_response); } curl_multi_remove_handle($mh, $curl_handlers[$i]); } curl_multi_close($mh); } return $enrollment_results; }
function parseTweet($s) { return parseTags(parseNames(parseLinks($s))); }