$res = preg_replace( "|/[^\/\.]+\.[^\/\.]+$|", '', $res[0] ); $res = rtrim( $res, '/' ); if ( ( $root = @parse_url( $res ) ) ) { $root = $root['scheme'] .'://'. $root['host']; } else { // fixme // die( 'Unable to parse: '.$res ); $root = 'http://'; } $search = array( "|^(\/)|i", "|^(?!http://)(?!mailto:)|i", "|/\./|", "|/[^\/]+/\.\./|" ); $replace = array( $root .'/', $res . '/', '/', '/' ); return preg_replace( $search, $replace, $link ); } // }}} function fetch( $url, $params=array() ) { // {{{ global $config; if ( ( $host = @parse_url( $url ) ) && linkex::get( 'host', $host, false ) !== false ) { $po = linkex::get( 'port', $host, '80' ); $ho = linkex::get( 'host', $host, '' ); $pa = linkex::get( 'path', $host ); $pa = ( strlen( $pa ) == 0 ) ? '/':$pa; $qu = linkex::get( 'query', $host, '' ); $pa.= ( strlen( $qu ) == 0 ) ? '':'?'.$qu; $cua = array_map( 'trim', explode("\n", $config->linkbotagent ) ); shuffle($cua); $cua = $cua[0]; $ua = linkex::get( 'agent', $params, $cua ); $h = array(); $h[]= linkex::get( 'method', $params, 'GET' ).' '.$pa.' HTTP/1.0'; $h[]= 'Host: '.$ho; $h[]= 'User-Agent: '.$ua; $h[]= 'Connection: close'; if ( ( $ref = linkex::get( 'referer', $params, false ) ) !== false ) { $h[] = 'Referer: '.$ref; } if ( linkex::get( 'method', $params, 'GET' ) == 'POST' && strlen( linkex::get( 'data', $params, '' ) ) > 0 ) { $h[]= 'Content-Length: '.strlen( linkex::get( 'data', $params, '' ) ); $h[] = 'Content-Type: application/x-www-form-urlencoded'; } $header = join( "\r\n", $h ) . "\r\n\r\n"; if ( ( $data = linkex::get( 'data', $params, false ) ) !== false ) { $header .= $data; } $buffer = ''; $fp = @fsockopen ( $ho, $po, $errno, $error, linkex::get( 'timeout', $params, 3 ) ); if ( !$fp ) { return array( 'URL' => $url, 'error' => 'Socket error: '.$error.' ['.$errno.']' ); } else { fputs( $fp, $header ); while( !feof( $fp ) ) { $buffer .= fgets( $fp, 1024 ); } fclose( $fp ); /// buffer holder nu hele resultatet, incl headers etc if ( preg_match( '/^HTTP\/(\d+\.\d+)\s+(\d{3})\s+(.*)/i', $buffer, $res ) === false ) { return array( 'URL' => $url, 'error' => 'Invalid HTTP response ('.substr( $buffer,0,30).')' ); } else { switch ( $res[2] ) { case 200: /// ok /// strip off the headers $res = explode( "\n\n", str_replace( chr( 13 ), '', $buffer ) ); if ( sizeof( $res ) >= 2 ) { $headers = array_shift( $res ); if ( function_exists( 'utf8_encode' ) ) { $contents = utf8_encode( join( "\n\n", $res ) ); } else { $contents = join( "\n\n", $res ); } return array( 'URL' => $url, 'headers' => $headers, 'contents' => $contents ); } else { return array( 'URL' => $url, 'contents' => utf8_encode( $buffer ) ); } break; case 301: case 302: /// maybe redirect? if ( !preg_match( '/location\:\s+(.*)/i', $buffer, $redir ) ) { return array( 'URL' => $url, 'error' => $res[2].' but no redirect' ); } else { $url = rtrim( $redir[1] ); if ( !preg_match( '"^http"i', $url ) ) { $url = 'http://'.$ho.'/'.ltrim( $url, '/' ); } if ( ( $h = @parse_url( $url ) ) === false ) { return array( 'URL' => $url, 'error' => $res[2].' but unparsable URL' ); } else { if ( str_replace( 'www.', '', strtolower( linkex::get( 'host', $h, '' ) ) ) != str_replace( 'www.','', strtolower( $ho ) ) ) { return array( 'URL' => $url, 'error' => $res[2].' but to external site ('.linkex::get( 'host', $h, '' ).')' ); } else { return linkex::fetch( trim( $url ) ); } } } } // }}} function map( $fun, $arr ) { // {{{ $retval = array(); foreach( $arr AS $k=>$v ) { $retval[ $k ] = $fun( $v ); } return $retval; } // }}} function mail( $to, $sub, $body ) { // {{{ global $config; $headers = array(); $headers[] = 'X-Mailer: LinkEX/20090302'; if ( strlen( $config->email ) > 0 ) { $headers[] = sprintf( 'From: LinkEX @ %s <%s>', linkex::get( 'HTTP_HOST', $_SERVER, linkex::getdomain( $config->url ) ), $config->email ); $headers[] = sprintf( 'Reply-To: %s', trim( $config->email ) ); } return mail( $to, $sub, $body, join( str_replace( array( '\r', '\n' ), array( "\r", "\n" ), $config->emailcrlf ), $headers ) ); } // }}} function redirect( $url, $code=301 ) { // {{{ $resp = array( 301 => 'HTTP/1.1 301 Moved Permanently', 404 => 'HTTP/1.1 404 Not Found' ); if ( ( $resp = linkex::get( $code, $resp, false ) ) !== false ) { header( $resp ); } header( 'location: '.$url ); exit; } // }}} function selector( $name, $list, $selected=null, $multiple=true, $forcetype=null, $extra=null, $sep='
' ) { /// {{{ $type = ( $multiple ) ? 'checkbox':'radio'; $type = ( sizeof( $list ) > 5 ) ? 'select':$type; if ( $forcetype && in_array( $forcetype, array( 'checkbox', 'radio', 'select' ) ) ) { $type = $forcetype; } $extra['class'] = $type.' '.linkex::get( 'class', $extra, '' ); if ( $extra ) { $buffer=array(); foreach( $extra AS $k=>$v ) { $buffer[] = sprintf( '%s="%s"', $k, $v ); } $extra=' '.join( ' ', $buffer ); } else { $extra=''; } $formname = ( $multiple ) ? $name.'[]' : $name; $buffer = ''; if ( $type == 'select' ) { $buffer .= sprintf( ' %s%s', $formname, $id, ($ck)?' checked="checked"':'', $extra, $txt, $sep ); } elseif ( $type == 'radio' ) { $buffer .= sprintf( '%s', $formname, $id, ($ck)?' checked="checked"':'', $extra, $txt, $sep ); } } if ( $type == 'select' ) { $buffer .= ''; } return $buffer; } /// }}} function serialize( $val ) { // {{{ return serialize( $val ); } // }}} function sort( &$array, $field, $order='desc' ) { // {{{ if ( $field == 'random' ) { shuffle( $array ); } else { $GLOBALS['sortby'] = $field; usort( $array, array( 'linkex', 'usort' ) ); if ( $order == 'desc' ) { $array = array_reverse( $array ); } } } // }}} function stripcomments( $con ) { // {{{ $con = preg_replace( '||Umis', '', $con ); $con = preg_replace( '||Umis', '', $con ); $con = preg_replace( '||Umis', '', $con ); return $con; } // }}} function substr( $str, $len, $pad='..' ) { // {{{ if ( strlen( $str ) > $len ) { return substr( $str, 0, $len - strlen( $pad ) ) . $pad; } else { return $str; } } // }}} function truncate( $str, $len, $txt='..' ) { // {{{ if ( strlen( $str ) > ( $len-strlen( $txt ) ) ) { return substr( $str, 0, $len-strlen( $txt ) ).$txt; } else { return $str; } } // }}} function unserialize( $str ) { // {{{ $retval = @unserialize( $str ); if ( $retval !== false ) { return $retval; } else { // Attempt to fix it $str = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", trim( $str ) ); $retval = @unserialize( $str ); if ( $retval !== false ) { return $retval; } else { echo '[Fatal error in linkex::unserialize( "'. $str .'" )]'; } } } // }}} function usort( $a, $b ) { // {{{ if ( isset( $GLOBALS['sortby'] ) && strlen( $GLOBALS['sortby'] ) > 0 ) { $f = $GLOBALS['sortby']; if ( is_object( $a ) && isset( $a->$f ) ) { $aa = $a->$f; } else if ( is_array( $a ) && isset( $a[$f] ) ) { $aa = $a[$f]; } else { $aa = $a; } if ( is_object( $b ) && isset( $b->$f ) ) { $bb = $b->$f; } else if ( is_array( $b ) && isset( $b[$f] ) ) { $bb = $b[$f]; } else { $bb = $b; } switch( $f ) { case 'rdomip': $aa = sprintf( '%u', ip2long( $aa ) ); $bb = sprintf( '%u', ip2long( $bb ) ); break; case 'rdom': $aa = str_replace( 'www.', '', strtolower( $aa ) ); $bb = str_replace( 'www.', '', strtolower( $bb ) ); break; case 'anchor': $aa = strtolower( $aa ); $bb = strtolower( $bb ); break; } if ($aa == $bb) { return 0; } return ($aa < $bb) ? -1 : 1; } else { return 0; } } // }}} function verifybacklinks( $ids=array(), $callback=null ) { // {{{ global $config; $retval = array( 'starttime' => time(), 'links' => array(), 'categories' => array() ); foreach( $ids AS $id ) { $l = new link( $id ); $l->updateIPs(); $buffer = array( 'action' => 'link', 'id' => $l->id, 'rdom' => $l->rdom, 'rdomip' => $l->rdomip, 'rurl' => $l->rurl, 'skipcheck' => $l->skipcheck, 'skippagerank' => $l->skippagerank, 'minpagerank' => ( $l->minpagerank != -1 ) ? $l->minpagerank : $config->minpagerank, 'oldstatus' => $l->status, 'oldpagerank' => $l->pagerank ); if ( $l->skipcheck == 0 ) { $pr = $l->getPageRank(); $buffer{'res'} = $l->hasBacklink(); $buffer{'code'} = ( !is_string( linkex::get( 'reason', $buffer{'res'}, null ) ) ) ? '200 OK' : $l->laststatus; if ( $l->status != 4 ) { $l->status = ( ( $pr >= ( ( $l->minpagerank != -1 ) ? $l->minpagerank : $config->minpagerank ) ) && ( linkex::get( 'res', $buffer{'res'}, -1 ) == 0 ) ) ? 1:2; } if ( intval( $config->disableblacklisted ) == 1 && ( ( $b = $l->blacklisted() ) !== false )) { $l->status = 2; $buffer{'res'} = 64; $buffer{'code'} = $b; $l->log[] = array( 'date' => time(), 'res' => '64', 'reason' => $b ); } } else { $l->lastcheked = time(); $l->log[] = array( 'date' => time(), 'res' => '32', 'reason' => '' ); } $l->save( false ); $buffer{'status'} = $l->status; $buffer{'pagerank'} = $l->pagerank; $retval{'links'}[] = $buffer; unset( $l ); if ( $callback != null && function_exists( $callback ) ) { call_user_func( $callback, $buffer ); } unset( $buffer ); } // Rebuild categories $categories = linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'categories' . DIRECTORY_SEPARATOR ); foreach( $categories AS $cid ) { $c = new category( $cid ); $c->generate(); $buffer = array( 'action' => 'category', 'id' => $cid, 'name' => $c->name ); $retval{'categories'}[] = $buffer; unset( $c ); if ( $callback != null && function_exists( $callback ) ) { call_user_func( $callback, $buffer ); } unset( $buffer ); } $retval{'endtime'} = time(); return $retval; } // }}} function sum( $array = array() ) { // {{{ $retval = 0; foreach( $array AS $a ) { $retval += $a; } return $retval; } // }}} function yesno( $val ) { // {{{ return ( $val ) ? 'Yes':'No'; } // }}} } $category->filter = linkex::get( 'filter', $_POST, $category->filter ); $category->sortby = linkex::get( 'sortby', $_POST, $category->sortby ); $category->order = linkex::get( 'order', $_POST, $category->order ); $ca echo "\n\t\n\t\t{$navlinks}\n\t\n\n"; } echo "\t\t\n\t\n\n"; echo template::footer(); break; // }}} } break; case 'link': switch( linkex::get( 'action', $_REQUEST, 'overview' ) ) { case 'delete': // {{{ if ( ( $id = linkex::get( 'id', $_REQUEST, false ) ) !== false ) { $link = new Link( $id ); if ( sizeof( $_POST ) > 0 ) { $elems = linkex::get( 'blacklist', $_POST, array() ); foreach( $elems AS $e ) { $b = new Blacklist; $b->reason = 'Deleted'; switch( $e ) { case 'ldom': $b->type = 2; $b->value = $link->ldom; break; case 'ldomip': $b->type = 1; $b->value = $link->ldomip; break; case 'rdom': $b->type = 2; $b->value = $link->rdom; break; case 'rdomip': $b->type = 1; $b->value = $link->rdomip; break; case 'wmip': $b->type = 4; $b->value = $link->wmip; break; case 'edom': $b->type = 16; $b->value = $link->edom; break; case 'email': $b->type = 8; $b->value = $link->email; break; } if ( strlen( $b->value ) > 0 ) { $b->save(); } unset( $b ); } $link->delete(); linkex::redirect( BASEURI . '?page=admin' ); } else { $_SERVER['REQUEST_URI'] = htmlentities( $_SERVER['REQUEST_URI'] ); echo template::header( array( 'title' => 'Delete link [id:'.$id.']' ) ); echo "
\n\t
\n\t\tDelete link [id:{$id}]\n\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
Blacklist link domain "{$link->ldom}"
Blacklist link server IP "{$link->ldomip}"
Blacklist recip domain "{$link->rdom}"
Blacklist recip server IP "{$link->rdomip}"
Blacklist webmaster IP "{$link->wmip}"
Blacklist webmaster email domain "{$link->edom}"
Blacklist webmaster email "{$link->email}"
\n\t\t
\n\t
\n
\n\n"; echo template::footer(); } } else { linkex::redirect( BASEURI . '?page=admin' ); } break; // }}} case 'form': // {{{ if ( ( $id = linkex::get( 'id', $_REQUEST, false ) ) !== false ) { if ( file_exists( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR . $id ) ) { $link = new link( $id ); $link->updateIPs( false ); $pr = $link->getPageRank(); $link->save( false ); if ( sizeof( $_POST ) > 0 ) { $link->lurl = linkex::get( 'lurl', $_POST, '' ); $link->rurl = linkex::get( 'rurl', $_POST, '' ); $link->weight = intval( linkex::get( 'weight', $_POST, 0 ) ); $link->dateexpire = linkex::get( 'dateexpire', $_POST, '' ); $link->dateexpire = ( strlen( $link->dateexpire ) > 0 ) ? intval( @strtotime( $link->dateexpire ) ) : 0; $link->anchor = trim( linkex::get( 'anchor', $_POST, '' ) ); $link->description = htmlentities( trim( linkex::get( 'description', $_POST, '' ) ) ); $cats = $link->categories; $link->categories = linkex::get( 'categories', $_POST, array() ); if ( !is_array( $link->categories ) ) { $link->categories = array( intval( $link->categories ) ); } $cats = array_unique( array_merge( $cats, $link->categories ) ); $link->email = htmlentities( trim( linkex::get( 'email', $_POST, '' ) ) ); $link->skipcheck = intval( linkex::get( 'skipcheck', $_POST, 0 ) ); $link->skippagerank = intval( linkex::get( 'skippagerank', $_POST, 0 ) ); $link->minpagerank = intval( linkex::get( 'minpagerank', $_POST, -1 ) ); $link->status = linkex::get( 'status', $_POST, '0' ); $link->notes = linkex::get( 'notes', $_POST, '' ); $link->save( false ); foreach( $cats AS $cid ) { if ( file_exists( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'categories' . DIRECTORY_SEPARATOR . $cid ) ) { $c = new Category( $cid ); $c->generate(); unset( $c ); } } linkex::redirect( $_SERVER['REQUEST_URI'] ); } $pagerankcheckdatef = date( $config->dateformat, linkex::get( 'date', $link->pagerankinfo, 0 ) ); $_SERVER['REQUEST_URI'] = htmlentities( $_SERVER['REQUEST_URI'] ); $categories = linkex::categories( LOGGEDIN ); $categories = linkex::selector( 'categories', $categories, $link->categories, LOGGEDIN, null, array( 'style' => '' ) ); $status = linkex::selector( 'status', $link->statusOptions(), (string)$link->status, false, 'select' ); $skipcheck = linkex::checkbox( $link->skipcheck ); $skippagerank = linkex::checkbox( $link->skippagerank ); $minpagerank = linkex::selector( 'minpagerank', array( -1=>'Use global min. PageRank™', 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10 ), (string)$link->minpagerank, false, 'select', array( 'style' => 'width:auto;' ) ); $link->dateexpire = ( $link->dateexpire > 0 ) ? date( "Y-m-d", $link->dateexpire ) : ""; $laststatus = false; $lastcolor = false; $history = array_reverse( $link->log ); foreach( $history AS $hist ) { $res = ''; $color = 'red'; switch( $hist{'res'} ) { case '0': $res = '200 OK'; $color = 'green'; break; case '1': $res = $hist{'reason'}; break; case '2': $res = 'Missing backlink'; break; case '4': $res = 'Invalid anchor'; break; case '8': $res = 'Nofollow link'; break; case '16': $res = 'Too many external links'; break; case '32': $res = 'Check skipped'; $color = 'yellow'; break; case '64': $res = 'Blacklisted'; break; } $laststatus = ( $laststatus === false ) ? $res : $laststatus; $lastcolor = ( $lastcolor === false ) ? $color : $lastcolor; $h .= '
'.date( $config->dateformat, $hist{'date'} ).' ('.$res.")
"; } echo template::header( array( 'title' => 'Edit link [id:'.$id.'] ['.$link->rdom.']' ) ); echo "
\n\t
\n\t\t
\n\t\t\tLinking info\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
Link UID:{$link->id}
Added on:{$link->addedf}
Verified on:{$link->lastcheckedf} \n\t\t\t\t\t\t({$laststatus})\n\t\t\t\t\t\t(id}\">verify now)\n\t\t\t\t\t\t(History)\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t{$h}\n\t\t\t\t\t\t
\n\t\t\t\t\t
Added by:{$link->email} (edom}\" target=\"_blank\">whois) {$link->wmip} (wmip}\" target=\"_blank\">whois)
Link domain:lurl}\" target=\"_blank\">{$link->ldom} (ldom}\" target=\"_blank\">whois) {$link->ldomip} (ldomip}\" target=\"_blank\">whois)
Reciprocal domain:rurl}\" target=\"_blank\">{$link->rdom} (rdom}\" target=\"_blank\">whois) {$link->rdomip} (rdomip}\" target=\"_blank\">whois)
PageRank™:
  Last checked on: {$pagerankcheckdatef}

Site title:anchor}\" />
Link URL:lurl}\" />
Reciprocal link URL:rurl}\" />
Email:email}\" />
Site description:
Weight:weight}\" style=\"width:50px;\" />
Categories:{$categories}\n\t\t\t\t\t
Status:{$status}
Skip check:
Ignore PageRank™:
Min. PageRank™:{$minpagerank}

\n\t\t
\n\t
\n\n\n\t
\n\t\t\n\t
\n\n
\n\n"; echo template::footer(); } else { linkex::redirect( BASEURI . '?page=admin' ); } } else { linkex::redirect( BASEURI . '?page=admin' ); } break; // }}} } break; case 'verify': ob_implicit_flush(true); session_write_close(); $lid = linkex::get( 'lid', $_REQUEST, false ); // {{{ Mass delete if ( linkex::get( 'delete', $_POST, false ) !== false ) { if ( is_string( $lid ) ) { $lid = linkex::map( 'trim', explode( ',', $lid ) ); } else if ( is_int( $lid ) ) { $lid = array( $lid ); } if ( is_array( $lid ) ) { $categories = array(); foreach( $lid AS $id ) { $l = new link( $id ); if ( !is_array( $l->categories ) ) { $l->categories = array( $l->categories ); } $categories = array_merge( $categories, $l->categories ); unset( $l ); @unlink( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR . $id ); } $categories = array_unique( $categories ); foreach( $categories AS $cid ) { $c = new category( $cid ); $c->generate(); unset( $c ); } } linkex::redirect( BASEURI . '?page=admin' ); // }}} // {{{ Check to see if this is a mass edit } elseif ( linkex::get( 'massedit', $_POST, false ) !== false ) { if ( is_string( $lid ) ) { $lid = linkex::map( 'trim', explode( ',', $lid ) ); } else if ( is_int( $lid ) ) { $lid = array( $lid ); } if ( is_array( $lid ) ) { $updatecategories = array(); foreach( $lid AS $id ) { $l = new Link( $id ); $s = linkex::get( 'masseditsetstatus', $_POST, 0 ); if ( $s>0 ) { $l->status = $s; } $s = linkex::get( 'masseditskipcheck', $_POST, 0 ); if ( $s>0 ) { $l->skipcheck = ( $s==1 ) ? 1:0; } // <<< Added 29/12-2006 $s = linkex::get( 'masseditskippagerank', $_POST, 0 ); if ( $s>0 ) { $l->skippagerank = ( $s==1 ) ? 1:0; } // >>> $s = linkex::get( 'masseditminpagerank', $_POST, 'null' ); if ( $s != 'null' ) { $l->minpagerank = $s; } $s = linkex::get( 'masseditcategoryset', $_POST, 0 ); if ( $s == 1 ) { $updatecategories = array_unique( array_merge( $updatecategories, $l->categories ) ); $l->categories = array_unique( array_merge( $l->categories, linkex::get( 'masseditcategories', $_POST, array() ) ) ); $updatecategories = array_unique( array_merge( $updatecategories, $l->categories ) ); } else if ( $s == 2 ) { $updatecategories = array_unique( array_merge( $updatecategories, $l->categories ) ); $l->categories = linkex::get( 'masseditcategories', $_POST, array() ); $updatecategories = array_unique( array_merge( $updatecategories, $l->categories ) ); } $l->save( false ); unset( $l ); } foreach( $updatecategories AS $cid ) { if ( file_exists( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'categories' . DIRECTORY_SEPARATOR . $cid ) ) { $c = new Category( $cid ); $c->generate(); unset( $c ); } } } linkex::redirect( BASEURI . '?page=admin' ); } // }}} if ( $lid === false ) { $errors[] = 'You must select at least one link to verify.'; } if ( $lid == null ) { $lid = linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR ); } else if ( is_string( $lid ) ) { $lid = linkex::map( 'trim', explode( ',', $lid ) ); } else if ( is_int( $lid ) ) { $lid = array( $lid ); } if ( sizeof( $lid ) == 0 ) { $errors[] = 'You must select at least one link to verify..'; } echo template::header( array( 'title' => 'Verifying links' ) ); if ( sizeof( $errors ) == 0 ) { $legend = 'Verifying links...'; echo "\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{$legend}\n\t\t\t\t\t\t
    ID  Domain                         Status                                              PageRank BackL.Status
===============================================================================================================
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\n"; } echo template::footer(); linkex::flush(); $total = sizeof( $lid ); $current = 0; function updateProgress( $data ) { // {{{ global $total, $current; if ( $data{'action'} == 'link' ) { $current++; $title = sprintf( 'Verifying links... (%d%%)', $current/$total*100 ); $progress = sprintf( '% 6s % -30s % -50s '. '% 2s >=% 2s '. '% -3s '. '%s
', $data{'id'}, linkex::truncate( $data{'rdom'}, 30 ), ( $data{'skipcheck'} == 1 ) ? 'yellow': ( ( strpos( $data{'code'}, '200' ) !== false ) ? 'green':'red' ), ( $data{'skipcheck'} == 1 ) ? 'Skipped' : linkex::truncate( $data{'code'}, 50 ), ( $data{'skippagerank'} == 1 || $data{'skipcheck'} == 1 ) ? 'yellow': ( ( $data{'pagerank'} >= $data{'minpagerank'} ) ?'green':'red' ), $data{'pagerank'}, $data{'minpagerank'}, ( $data{'skipcheck'} == 1 ) ? 'yellow': ( ( linkex::get( 'res', $data{'res'}, -1 ) == 0 ) ? 'green':'red' ), ( $data{'skipcheck'} == 1 ) ? '-': ( ( linkex::get( 'res', $data{'res'}, -1 ) == 0 ) ? 'Yes':'No' ), ( $data{'skipcheck'} == 1 ) ? 'yellow': ( ( $data{'status'} == 1 ) ? 'green':'red' ), ( $data{'skipcheck'} == 1 ) ? 'Skipped' : link::statusOptions( $data{'status'} ) ); echo "\n"; linkex::flush(); } } // }}} linkex::verifybacklinks( $lid, 'updateProgress' ); exit; break; case 'settings': $rebuildcategories = false; $checkboxes = array( 'linkbotuniquedomains', 'disablepublicform', 'linkbotignoretrailingslash', 'linkbotdisregardwww', 'linkbackrequired', 'disablerecipfield', 'publiccategories', 'commandlineenable', 'commandlinesummary', 'remoteenable', 'remotesummary', 'remotelimitips', 'showemail', 'usecaptcha', 'verifyanchor', 'indexexchange', 'noquerystring', 'exposelinkex', 'rejectnofollow', 'disableblacklisted' ); // Save if posted if ( sizeof( $_POST ) > 0 ) { foreach( $checkboxes AS $b ) { $_POST[$b] = linkex::get( $b, $_POST, '0' ); } $config->htmlcode = htmlentities( stripslashes( $_POST['htmlcode'] ); $rebuildcategories = $rebuildcategories || ( $config->exposelinkex != linkex::get( 'exposelinkex', $_POST, 0 ) ); $config->exposelinkex = linkex::get( 'exposelinkex', $_POST, 0 ); $config->maxoutboundlinks = linkex::get( 'maxoutboundlinks', $_POST, 0 ); $crlf = linkex::get( 'emailcrlf', $_POST, '' ); if ( in_array( $crlf, array( '\r\n', '\n\r', '\n' ) ) ) { $config->emailcrlf = $crlf; } $config->rejectnofollow = linkex::get( 'rejectnofollow', $_POST, 0 ); $config->disableblacklisted = linkex::get( 'disableblacklisted', $_POST, 0 ); $config->indexexchange = linkex::get( 'indexexchange', $_POST, 0 ); $config->noquerystring = linkex::get( 'noquerystring', $_POST, 0 ); $config->samedomain = linkex::get( 'samedomain', $_POST, $config->samedomain ); $config->showemail = linkex::get( 'showemail', $_POST, 0 ); $config->usecaptcha = linkex::get( 'usecaptcha', $_POST, 0 ); $config->verifyanchor = intval( linkex::get( 'verifyanchor', $_POST, 0 ) ); $config->remotepass = linkex::get( 'remotepass', $_POST, '' ); $config->remoteips = linkex::map( 'trim', explode( "\n", linkex::get( 'remoteips', $_POST, '' ) ) ); $config->remoteenable = linkex::get( 'remoteenable', $_POST, 0 ); $config->remotesummary = linkex::get( 'remotesummary', $_POST, 0 ); $config->remotelimitips = linkex::get( 'remotelimitips', $_POST, 0 ); $config->commandlineenable = linkex::get( 'commandlineenable', $_POST, 0 ); $config->commandlinesummary = linkex::get( 'commandlinesummary', $_POST, 0 ); $config->googledatacenters = linkex::map( 'trim', explode( "\n", trim( linkex::get( 'googledatacenters', $_POST, '' ) ) ) ); $config->defaultcategories = linkex::get( 'categories', $_POST, array() ); $config->publiccategories = linkex::get( 'publiccategories', $_POST, $config->publiccategories ); $config->email = linkex::get( 'email', $_POST, $config->email ); $config->dateformat = linkex::get( 'dateformat', $_POST, $config->dateformat ); $config->charset = linkex::get( 'charset', $_POST, $config->charset ); $config->displaylimit = max( intval( linkex::get( 'displaylimit', $_POST, $config->displaylimit ) ), 1 ); $config->disablerecipfield = linkex::get( 'disablerecipfield', $_POST, $config->disablerecipfield ); $config->disablepublicform = linkex::get( 'disablepublicform', $_POST, $config->disablepublicform ); $config->sortkey = linkex::get( 'sortkey', $_POST, $config->sortkey ); $config->sortorder = linkex::get( 'sortorder', $_POST, $config->sortorder ); $config->url = linkex::get( 'url', $_POST, $config->url ); $config->anchor = linkex::map( 'trim', explode( "\n", linkex::get( 'anchor', $_POST, join( "\n", $config->anchor ) ) ) ); $config->description = linkex::get( 'description', $_POST, $config->description ); $config->altlinks = linkex::map( 'trim', explode( "\n", linkex::get( 'altlinks', $_POST, join( "\n", $config->altlinks ) ) ) ); $config->linkbotagent = linkex::get( 'linkbotagent', $_POST, $config->linkbotagent ); $config->linkbotuniquedomains = linkex::get( 'linkbotuniquedomains', $_POST, $config->linkbotuniquedomains ); $config->linkbotuniqueips = intval( linkex::get( 'linkbotuniqueips', $_POST, 0 ) ); $config->linkbotignoretrailingslash = linkex::get( 'linkbotignoretrailingslash', $_POST, $config->linkbotignoretrailingslash ); $config->linkbotdisregardwww = linkex::get( 'linkbotdisregardwww', $_POST, $config->linkbotdisregardwww ); $config->minpagerank = intval( linkex::get( 'minpagerank', $_POST, 0 ) ); $config->linkbackrequired = linkex::get( 'linkbackrequired', $_POST, $config->linkbackrequired ); // Lengths $config->titlelength = intval( linkex::get( 'titlelength', $_POST, 0 ) ); $config->titlelengthtype = linkex::get( 'titlelengthtype', $_POST, 'w' ); $config->descriptionlength = intval( linkex::get( 'descriptionlength', $_POST, 0 ) ); $config->descriptionlengthtype = linkex::get( 'descriptionlengthtype', $_POST, 'w' ); $config->maxoutboundtype = intval( linkex::get( 'maxoutboundtype', $_POST, 0 ) ); // Username/password $u = linkex::get( '_username', $_POST, false ); $p1 = linkex::get( '_password1', $_POST, false ); $p2 = linkex::get( '_password2', $_POST, false ); if ( $u && $p1 && $p1 == $p2 ) { $config->password = md5( $u .'---'. $p1 ); if ( linkex::get( 'username', $_COOKIE, false ) ) { setcookie( 'username', $u, time()+60*60*24*30, BASEURI ); setcookie( 'password', $p1, time()+60*60*24*30, BASEURI ); } $_SESSION['username'] = $u; $_SESSION['password'] = $p1; } $config->save(); $rules = linkex::get( 'rules', $_POST, '' ); if ( strlen( trim( $rules ) ) > 0 ) { linkex::fileput( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'rules', $rules ); } else { @unlink( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'rules' ); } // Should we rebuild the categories? if ( $rebuildcategories ) { $categories = linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'categories' . DIRECTORY_SEPARATOR ); foreach( $categories AS $cid ) { $c = new category( $cid ); $c->generate(); unset( $c ); } } linkex::redirect( $_SERVER['REQUEST_URI'] ); } $_SERVER['REQUEST_URI'] = htmlentities( linkex::get( 'REQUEST_URI', $_SERVER ) ); echo template::header( array( 'title' => 'Settings' ) ); $minpagerank = linkex::selector( 'minpagerank', range( 0,10 ), (string)$config->minpagerank, false, 'select', array( 'style' => 'width:60px;' ) ); $sortkey = linkex::selector( 'sortkey', array( 'added' => 'Date added', 'rdom' => 'Domain', 'rdomip' => 'IP', 'lastcheck' => 'Last checked', 'pagerank' => 'PageRank™', 'anchor' => 'Title' ), $config->sortkey, false, 'select' ); $sortorder = linkex::selector( 'sortorder', category::orders(), $config->sortorder, false, 'select', array( 'onchange' => 'modified=true;', 'style' => 'width:150px;' ) ); $samedomainselect = linkex::selector( 'samedomain', array( '0' => 'Does not matter', '1' => 'Must be on same domain', '2' => 'Must be on different domains' ), $config->samedomain, false, 'select', array( 'onchange' => 'modified=true;', 'style' => 'width:180px;' ) ); $anchor = join( "\n", $config->anchor ); $altlinks = join( "\n", $config->altlinks ); // Rewrite all checkbox values from [0|1] => [''|checked] foreach( $checkboxes AS $b ) { $config->$b = linkex::checkbox( $config->$b ); } $categories = linkex::selector( 'categories', linkex::categories( true ), $config->defaultcategories, true, 'checkbox', array( 'onchange' => 'modified=true;', 'style'=>'' ) ); $rules = linkex::fileget( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'rules', '' ); // The lenths of the input $titlelengthtype = linkex::selector( 'titlelengthtype', array( 'w' => 'words', 'c' => 'characters' ), $config->titlelengthtype, false, 'select', array( 'style' => 'width:100px;' ) ); $descriptionlengthtype = linkex::selector( 'descriptionlengthtype', array( 'w' => 'words', 'c' => 'characters' ), $config->descriptionlengthtype, false, 'select', array( 'style' => 'width:100px;' ) ); $maxoutboundtypeselect = linkex::selector( 'maxoutboundtype', array( 0 => 'incl. nofollow', 1 => 'excl. nofollow' ), strval( $config->maxoutboundtype ), false, 'select', array( 'style' => 'width:100px;' ) ); $remoteips = join( "\n", $config->remoteips ); $googledatacenters = join( "\n", $config->googledatacenters ); $copyright = htmlentities( "\n" ); echo "
\n\t
\n\t\t
\n\t\t\tAdmin settings\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
Username:
Password:
Password (again):
Email:email}\" />
Date format:dateformat}\" />
Charset:charset}\" />
Display limit:displaylimit}\" style=\"width:40px;\" />
Email CRLF:emailcrlf}\" style=\"width:40px;\" />
Default sort key:{$sortkey}
Default sort order:{$sortorder}
Disable public form:disablepublicform} />
Show email:showemail} />
Use CAPTCHA:usecaptcha} />
\n\t\t\t
\n\t\t
\n\t
\n\n\t
\n\t\t
\n\t\t\tCategory settings\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t
Public categories:\n\t\t\t\t\t\t\tpubliccategories} />\n\t\t\t\t\t\t\t
Default categories:{$categories}
Expose LinkEX:\n\t\t\t\t\t\t\texposelinkex} />\n\t\t\t\t\t\t\t\tShow {$copyright} in top of category outout\n\t\t\t\t\t\t
\n\t\t\t
\n\t\t
\n\t
\n\n\n\t
\n\t\t
\n\t\t\tLinking settings\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
Website URL:url}\" />
Website title:
(one pr. line)
Description:
Alternative backlinks:
(one pr. line)
Rules:
HMTL code:\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t{$URL} - Website URL
\n\t\t\t\t\t\t\t\t{$ANCHOR} - A random selected title
\n\t\t\t\t\t\t\t\t{$DESCRIPTION} - Description\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t
\n\t\t
\n\t
\n\n\t
\n\t\t\n\t
\n\n\t
\n\t\t
\n\t\t\tCommand line settings\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
Enable:commandlineenable} />
Send summary:commandlinesummary} />
\n\t\t\t
\n\t\t
\n\t
\n\n\t
\n\t\t
\n\t\t\tRemote access settings\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
Enable:remoteenable} />
Send email summary:remotesummary} />
Remote passphrase:remotepass}\" />
Limit IPs:remotelimitips} />
Accepted IPs
(one pr. line)
\n\t\t\t
\n\t\t
\n\t
\n\n\n\t
\n\n
\n\n"; echo template::footer(); break; case 'tools': switch( linkex::get( 'action', $_REQUEST, 'overview' ) ) { case 'autoadd': // {{{ ob_implicit_flush(true); session_write_close(); echo template::header( array( 'title' => 'Tools' ) ); $_POST['url'] = linkex::get( 'url', $_POST, $config->url ); $_POST['data'] = linkex::get( 'data', $_POST, '' ); if ( strlen( trim( $_POST['data'] ) ) > 0 ) { $legend = 'Adding links'; echo "\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{$legend}\n\t\t\t\t\t\t
    ID  Domain                         Status                                              PageRank BackL.Status
===============================================================================================================
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\n"; echo template::footer(); linkex::flush(); $links = array_map( 'trim', explode( "\n", trim( $_POST['data'] ) ) ); foreach ( $links AS $link ) { $dom = linkex::getDomain( str_replace( 'www.', '', strtolower( $link ) ) ); template::progress( sprintf( "%-15s", substr( $dom, 0, 14 ) ) ); $con = linkex::fetch( $link ); if ( preg_match( '#^HTTP/\d+\.\d+\s+200#', linkex::get( 'headers', $con, '' ) ) ) { $f=0; foreach( autoadd::knownscripts() AS $script=>$regex ) { if ( preg_match( $regex, $con{'contents'} ) ) { template::progress( sprintf( '[ %-13s ]', $script ) ); $f=1; $res = autoadd::$script( $con, $_POST['url'] ); if ( $res === true ) { template::progress( ' [ OK ]' ); } else { template::progress( ' [ '.$res.' ]' ); } break; } } if ( $f==0 ) { template::progress( '[ Link Script not recognized ]' ); } } else { template::progress( sprintf( ' [ ERROR: Invalid response %-20s ]', linkex::get( 'headers', $con ) ) ); } template::progress( '
' ); } exit; } else { $cat = $config->defaultcategories; $categories = linkex::categories( LOGGEDIN ); $cats = array(); foreach( $categories AS $cid=>$name ) { $cats[] = new Category( $cid ); } $categories = $cats; unset( $cats ); linkex::sort( $categories, 'name', 'asc' ); $cats = array(); foreach( $categories AS $c ) { $cats{ $c->id } = $c->name; } $categories = $cats; unset( $cats ); $categories = linkex::selector( 'categories', $categories, linkex::get( 'categories', $_POST, $cat ), LOGGEDIN, null, array( 'style' => '' ) ); $formaction = htmlentities( $_SERVER['REQUEST_URI'] ); echo "
\n\t
\n\t\tLinking Details\n\t\t
\n\n\t\t\t\n\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
URL:
Categories:{$categories}
Link Sites:
\n\t\t\t\t\t\t(One URL pr. line)
\n\t\t\t\t\t(URL to trade form)

\n\t\t
\n\t
\n
\n"; } echo template::footer(); break; // }}} case 'email': // {{{ $linkids = linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR ); $list = array(); $email2id = array(); foreach( $linkids AS $lid ) { $l = new link( $lid ); if ( strlen( $l->email ) > 0 ) { if ( linkex::get( $l->email, $list, false ) === false ) { $list[ $l->email ] = array( $l->ldom ); $email2id[ $l->email ] = array( $l->id ); } else { $list[ $l->email ][] = $l->ldom; $email2id[ $l->email ][] = $l->id; } } } if ( linkex::get( 'subject', $_POST, false ) !== false && linkex::get( 'sendto', $_POST, false ) !== false ) { echo template::header( array( 'title' => 'Tools » Send email' ) ); $subject = linkex::get( 'subject', $_POST, '' ); $body = linkex::get( 'body', $_POST, '' ); $sendto = linkex::get( 'sendto', $_POST, array() ); $ids = array(); foreach( $sendto AS $to ) { $ids = $ids + linkex::get( $to, $email2id, array() ); } foreach( $ids AS $id ) { $l = new link( $id ); linkex::mail( $l->email, $subject, $body ); } echo "Done sending mails.."; echo template::footer(); } else { $emails = array(); foreach( $list AS $e=>$l ) { $emails[ $e ] = sprintf( '%s (%s)', $e, join(', ',$l ) ); } $selected = linkex::get( 'sendto', $_REQUEST, array() ); if ( is_string( $selected ) ) { $selected = explode( ',', $selected ); } $emails = linkex::selector( 'sendto', $emails, $selected, true, 'select', array( 'style'=>'width:400px;' ) ); $_SERVER['REQUEST_URI'] = htmlentities( $_SERVER['REQUEST_URI'] ); echo template::header( array( 'title' => 'Tools » Send email' ) ); echo "
\n\t
\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
To:{$emails}
Subject:
Message:
\n\t\t\t\t\t\n\t\t\t\t
\n\t
\n
\n\n"; echo template::footer(); } break; // }}} case 'import': // {{{ echo template::header( array( 'title' => 'Tools » Import' ) ); if ( linkex::get( 'seperator', $_POST, false ) && linkex::get( 'input', $_POST, false ) ) { if ( linkex::get( 'unique', $_POST, false ) !== false ) { $doms = array(); // We need to make sure the domains are unique, so we make a list of all out domains $linkids = linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR ); foreach ( $linkids AS $lid ) { $l = new link( $lid ); $doms[] = $l->ldom; unset( $l ); } } $seperator = preg_quote( linkex::get( 'seperator', $_POST, '' ), '#' ); $fields = explode( ',', linkex::get( 'fields', $_POST, '' ) ); $field_count = sizeof( $fields ); $categories = linkex::get( 'categories', $_POST, $config->defaultcategories ); $verify = linkex::get( 'verify', $_POST, 0 ); $lines = explode( "\n", str_replace( "\r", '', linkex::get( 'input', $_POST, '' ) ) ); $legend = 'Adding new links...'; echo "\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{$legend}\n\t\t\t\t\t\t
    ID  Domain                         Status                                              PageRank BackL.Status
===============================================================================================================
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\n"; echo template::footer(); flush(); $progress = ''; $title = ''; foreach( $lines AS $line ) { $list = preg_split( "#".$seperator."#", trim( $line ) ); if ( sizeof( $list ) == sizeof( $fields ) ) { $l = new link; for( $i=0; $iemail = $list[$i]; break; case 'rurl': $l->rurl = $list[$i]; break; case 'lurl': $l->lurl = $list[$i]; break; case 'anchor': $l->anchor = $list[$i]; break; case 'description': $l->description = $list[$i]; break; case 'randlurl': $l->lurl = $list[$i]; $l->rurl = $list[$i]; break; } } $l->update(); if ( ( $verify==1 && ( $res = $l->hasBacklink() ) && linkex::get( 'res', $res, 0 ) != 0 ) ) { $p = sprintf( 'Skipping line due to missing backlink
  (%s)', trim( $line ) ); } elseif ( linkex::get( 'unique', $_POST, false ) !== false && sizeof( $doms ) > 0 && in_array( $l->ldom, $doms ) ) { $p = sprintf( 'Skipping line since there allready exists a link to %s', $l->ldom ); } else { $l->categories = $categories; $l->save(); $p = sprintf( 'Added link' ); } } else { $p = sprintf( 'Skipping line due to mismatch in field count
  (%s)', trim( $line ) ); } printf( '', $p ); flush(); } } else { $_SERVER['REQUEST_URI'] = htmlentities( $_SERVER['REQUEST_URI'] ); $categories = linkex::categories( true ); $categories = linkex::selector( 'categories', $categories ); echo "
\n\t
\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
Input seperator:\n\t\t\t\t\t\n\t\t\t\t\t(tip: use \t for tab, or \s+ for one or more space characters)\n\t\t\t\t
Input fields:\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t« \n\t\t\t\t\t\t\t\t»\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t
\n\t\t\t\t
Input example:
Categories:{$categories}
Verify linkback: (only links with a valid backlink will be imported)
Unique domains: (Do not import links when there allready exists links to same domain)
Input:
\n\t
\n
\n\n\n\n"; echo template::footer(); } break; // }}} case 'overview': // {{{ echo template::header( array( 'title' => 'Tools' ) ); echo "
\n\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
Mass addBatch import links into LinkEX
Send emailSend an email to one or more webmasters
AutoaddAutomatically add your site to other link exchange scripts.
(BETA. Let me know how it works for you)
Pagerank TestHaving problems with PageRank? Use this tool to debug the communication with Google.
\n
\n"; echo template::footer(); break; // }}} case 'pageranktest': // {{{ echo << LinkEX » Test Pagerank algorithm
END;

	$pr = new PageRank;
	$url = 'http://linkex.dk';
	echo "Testing pagerank for: $url\n";
	echo "Calculation Google Cookie (expecting 773196802182)\n";
	$cookie = $pr->getCH( $url );
	echo "  $cookie - ";
	if ( $cookie == "773196802182" ) {
		echo "passed\n";

		$host = $pr->hosts[ mt_rand( 0, sizeof( $pr->hosts ) - 1 ) ];
		$ip = linkex::gethostbyname( $host, true );
		echo "Requesting info from Google (using $host - $ip)\n";
		$fp = fsockopen( $ip, 80, $errno, $error, 2 );
		if ( $fp ) {
			$header = '';
			$header .= "GET /search?client=navclient-auto&ch=" . $cookie .  "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n" ;
			$header .= "Host: ".$host."\r\n" ;
			$header .= "Connection: Close\r\n\r\n" ;
			fwrite( $fp, $header );
			$data = '';
			while ( !feof( $fp ) ) {
				$data .= fgets( $fp, 128 );
			}
			fclose( $fp );
			if ( preg_match( '#(HTTP/\d+\.\d+\s+(\d{3}))#Umis', $data, $res ) ) {
				if ( $res[2] == '200' ) {
					echo "  ".$res[1]."\n";
					if ( ( $pos = strpos( $data, 'Rank_' ) ) !== false ) {
						$pagerank = intval( trim( substr( $data, $pos + 9 ) ) );
						echo "  PageRank for $url - $pagerank\n";
						echo "  Test ended successfully\n";
					} else {
						echo "  Did not find Rank_ in body of document\n";
						echo "\n".htmlentities( $data );
					}
				} else {
					echo "\n".htmlentities( $data );
				}
			} else {
				$data = explode( "\n", str_replace( "\r", '', $data ) );
				echo "  Get invalid response from $host - ".$data[0]."\n";
			}
		} else {
			echo "  unable to create socket to $host - $error\n";
		}
	} else {
		echo "failed\n";
	}
	echo <<
	

END;
	break; // }}}
}

					break;
				case 'upgrade':

function debug( $str ) { // {{{
	echo "";
	linkex::flush();
} // }}}

echo template::header( array( 'title' => 'Upgrading  LinkEX' ) );
$legend = 'Upgrading LinkEX';
echo "\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{$legend}\n\t\t\t\t\t\t
    ID  Domain                         Status                                              PageRank BackL.Status
===============================================================================================================
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\n"; echo template::footer(); linkex::flush(); if ( ( $fp = @fopen( 'index.php', 'a' ) ) === false ) { // Unable to write to index.php debug( 'Cannot open index.php for writing. Please check the permissions.' ); exit; } fclose ( $fp ); debug( 'Cheking file permissions.. done' ); if ( @copy( __FILE__, BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'index.'.date( 'Ymd' ).'.php' ) === false ) { debug( 'Unable to backup LinkEX script' ); exit; } debug( 'Backing up current version.. done' ); $md5 = linkex::fetch( 'http://linkex.dk/releases/current.md5' ); if ( ( $error = linkex::get( 'error', $md5, false ) ) !== false ) { debug( 'Error while fetching version checkum ('.$md5['error'].')' ); exit; } else if ( strlen( trim( linkex::get( 'contents', $md5, '' ) ) ) != 32 ) { debug( 'Invalid response while fetching version checksum.' ); exit; } $checksum = trim( linkex::get( 'contents', $md5, '' ) ); debug( 'Fetching new version checksum.. ['.$checksum.']' ); $script = linkex::fetch( 'http://linkex.dk/releases/current.tar' ); if ( ( $error = linkex::get( 'error', $md5, false ) ) !== false ) { debug( 'Error while fetching new script ['.$md5['error'].']' ); exit; } $script = linkex::get( 'contents', $script, '' ); debug( 'Fetching new version data file.. done ['.round(strlen($script)/1024,1).'kb]' ); if ( strcmp( strtolower( md5( $script ) ), strtolower( $checksum ) ) != 0 ) { debug( 'Verifying script checksum.. Error! Checksum mismatch ['.md5( $script).']' ); exit; } debug( 'Verifying script checksum.. done' ); linkex::fileput( __FILE__, $script ); debug( 'Installing new version.. done' ); debug( '
Upgrade complete.' ); break; default: linkex::redirect( BASEURI, 404 ); } } else { echo template::header( array( 'title' => 'Please login', 'metarobots' => 'noindex,follow' ) ); echo "
\n\t
\n\t\tPlease login\n\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
Username:
Password:
I have forgotten my username/password
\n\t\t
\n\t
\n
\n"; echo template::footer(); } break; case 'check': @set_time_limit( 0 ); // Remote check function checkoutput( $code, $str ) { // {{{ die( "{$code}:{$str}\n" ); } // }}} // {{{ Is this thing enabled? if ( intval( $config->remoteenable ) == 0 ) { checkoutput( 1, 'Remote access is not enabled' ); } // }}} // {{{ IP check if ( intval( $config->remotelimitips ) == 1 ) { $ips = $config->remoteips; $found = false; $remote = linkex::get( 'REMOTE_ADDR', $_SERVER, '' ); foreach( $ips AS $ip ) { if ( linkex::compareIPs( $ip, $remote ) == 0 ) { $found = true; break; } } if ( $found !== true ) { checkoutput( 2, 'Your IP ('.$remote.') is not in the accepted IP list' ); } } // }}} // {{{ Passphrase check if ( ( $pass = $config->remotepass ) && strlen( $pass ) > 0 ) { if ( linkex::get( 'passphrase', $_GET, false ) != $pass ) { checkoutput( 3, 'Invalid or missing passphrase' ); } } // }}} $report = linkex::verifybacklinks( linkex::listfiles( BASEDIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'links' . DIRECTORY_SEPARATOR ) ); if ( $config->remotesummary == 1 ) { $report = template::report( $report ); linkex::mail( $config->email, 'Link verification report', $report ); } checkoutput( 0, 'OK' ); break; case 'about': echo template::header( array( 'title' => 'About', 'metarobots' => 'noindex,follow' ) ); echo template::about(); echo template::footer(); break; case 'logout': $path = dirname( linkex::get( 'SCRIPT_NAME', $_SERVER, '/' ) ); setcookie( '_authcookie', '', time() - 3600, $path ); unset( $_SESSION['_authcookie'] ); linkex::redirect( BASEURI, 301 ); case '': // Add link if ( !LOGGEDIN && intval( $config->disablepublicform ) == 1 ) { echo template::header( array( 'title' => 'Add link', 'metadescription' => 'Exchange hardlinks with '.$config->domain ) ); echo "
\n\t
\n\t\tForm disabled\n\t\t
\n\t\t\tPlease contact the webmaster to setup a link trade.\n\t\t
\n\t
\n
\n"; echo template::footer(); } else { if ( sizeof( $_POST ) > 0 ) { if ( ( intval( $config->usecaptcha ) == 0 ) || ( intval( $config->usecaptcha ) == 1 && linkex::get( 'captcha', $_POST, false ) && linkex::get( 'captcha', $_SESSION, false ) && linkex::get( 'result', $_SESSION['captcha'], false ) && $_POST['captcha'] == $_SESSION['captcha']['result'] ) ) { $link = new link; $link->wmip = $_SERVER['REMOTE_ADDR']; $link->lurl = htmlentities( linkex::get( 'lurl', $_POST, '' ) ); if ( $config->disablerecipfield == 1 && !LOGGEDIN && $config->samedomain != 2 ) { $link->rurl = $link->lurl; } else { $link->rurl = htmlentities( linkex::get( 'rurl', $_POST, '' ) ); } // Damn stupid noobish exploit $link->anchor = htmlentities( trim( linkex::get( 'anchor', $_POST, '' ) ) ); $link->description = htmlentities( trim( linkex::get( 'description', $_POST, '' ) ) ); $link->categories = linkex::get( 'categories', $_POST, $config->defaultcategories ); if ( !is_array( $link->categories ) ) { $link->categories = array( $link->categories ); } $link->categories = linkex::map( 'intval', $link->categories ); $link->email = htmlentities( trim( linkex::get( 'email', $_POST, '' ) ) ); // Start link validation // {{{ Check the anchor if ( strlen( $link->anchor ) == 0 ) { $errors[] = 'Please fill out the title'; } // }}} // {{{ Check the lurl if ( strlen( $link->lurl ) == 0 ) { $errors[] = 'Please fill out the URL'; } else if ( !preg_match( '/^https?:\/\/(.*\.)*[a-z0-9]([a-z0-9-]*[a-z0-9])?\.[a-z]+(.*)?/i', $link->lurl ) ) { $errors[] = 'The URL "'.$link->lurl.'" in invalid'; } // }}} // {{{ Check the email if ( strlen( $link->email ) == 0 ) { $errors[] = 'Please enter an email address'; } else if ( !preg_match( '/\S+@[a-z0-9]([a-z0-9-]*[a-z0-9])?\.[a-z]+(.*)?/i', $link->email ) ) { $errors[] = 'The email "'.$link->email.'" is invalid'; } // }}} // {{{ Check the rurl if ( intval( $config->disablerecipfield ) == 0 ) { if ( strlen( $link->rurl ) == 0 ) { $errors[] = 'Please fill out the reprocial URL'; } else if ( !preg_match( '/^https?:\/\/(.*\.)*[a-z0-9]([a-z0-9-]*[a-z0-9])?\.[a-z]+(.*)?/i', $link->rurl ) ) { $errors[] = 'The reprocial URL "'.$link->rurl.'" in invalid'; } } // }}} // {{{ Check the categories if ( $config->publiccategories == 1 ) { if ( sizeof( $link->categories ) == 0 ) { $errors[] = 'Please select a category'; } } // }}} $link->update(); $link->updateIPs(); // {{{ indexexchange if ( $config->indexexchange == 1 ) { $elems = @parse_url( $link->lurl ); if ( linkex::get( 'path', $elems, '/' ) != '/' ) { $errors[] = 'Only index exchanges allowed'; } if ( $link->lurl != $link->rurl ) { $elems = @parse_url( $link->rurl ); if ( linkex::get( 'path', $elems, '/' ) != '/' ) { $errors[] = 'Only index exchanges allowed'; } } } // }}} // {{{ noquerystring if ( $config->noquerystring == 1 ) { if ( strpos( $link->lurl, '?' ) !== false ) { $errors[] = 'No querystrings allowed'; } if ( $link->rurl != $link->lurl && strpos( $link->rurl, '?' ) !== false ) { $errors[] = 'No querystrings allowed'; } } // }}} // {{{ Same domain? switch( intval( $config->samedomain ) ) { case 1: if ( linkex::compareURLs( $link->ldom, $link->rdom ) != 0 ) { $errors[] = 'The submitted URLs must be on the same domain'; } break; case 2: if ( intval( $config->disablerecipfield ) == 0 && linkex::compareURLs( $link->ldom, $link->rdom ) == 0 ) { $errors[] = 'The submitted URLs must be on different domains'; } break; } // }}} // {{{ Check the length's if ( sizeof( $errors ) == 0 && (( LOGGEDIN && linkex::get( 'skiplengths', $_POST, 0 ) == 0 ) || !LOGGEDIN ) ) { // First the title if ( $config->titlelength > 0 ) { if ( $config->titlelengthtype == 'w' ) { // Max words if ( sizeof( preg_split( '#\s+#', $link->anchor ) ) > $config->titlelength ) { $errors[] = sprintf( 'Your site title is too long' ); } } else { // Max len if ( strlen( $link->anchor ) > $config->titlelength ) { $errors[] = sprintf( 'Your site title is too long' ); } } } // Then the description if ( $config->descriptionlength > 0 ) { if ( $config->descriptionlengthtype == 'w' ) { // Max words if ( sizeof( preg_split( '#\s+#', $link->description ) ) > $config->descriptionlength ) { $errors[] = sprintf( 'Your site description is too long' ); } } else { // Max len