Try to determine if a URL is pointing to internal content.

@param $url
@param int $pos (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...

@return bool|string
431119
protected function fuzzyHrefMatch( $url, $pos ) {
		if ( ! $pos ) {
			return false;
		}

		$url = trim( $url );
		// Remove trailing slash
		$url = rtrim( $url, '/' );
		// Change /foo/bar/#fragment to /foo/bar#fragment
		if ( preg_match( '~/#[^/]*$~', $url ) ) {
			$url = str_lreplace( '/#', '#', $url );
		}

		$domain = wp_parse_url( $url );
		$domain = ( isset( $domain['host'] ) ) ? $domain['host'] : false;

		if ( $domain ) {
			$guess_url = site_url();
			if ( ! $guess_url ) {
				$guess_url = wp_guess_url();
			}
			$domain2 = wp_parse_url( $guess_url );
			$domain2 = ( isset( $domain2['host'] ) ) ? $domain2['host'] : false;
			if ( $domain2 !== $domain ) {
				return false; // If there is a domain name and it =/= ours, bail.
			}
		}

		$split_url = explode( '/', $url );
		$last_pos = count( $split_url ) - 1;
		$posttype = ( isset( $split_url[ $last_pos - 1 ] ) ) ? $split_url[ $last_pos - 1 ] : false;
		$anchor = '';

		// Guess the slug
		if ( $last_pos > 0 && '#' === substr( trim( $split_url[ $last_pos ] ), 0, 1 ) ) {
			$anchor = trim( $split_url[ $last_pos ] ); // Found an #anchor
			$slug = trim( $split_url[ $last_pos - 1 ] );
		} elseif ( false !== strpos( $split_url[ $last_pos ], '#' ) ) {
			list( $slug, $anchor ) = explode( '#', $split_url[ $last_pos ] ); // Found an #anchor
			$anchor = trim( "#{$anchor}" );
			$slug = trim( $slug );
		} else {
			$slug = trim( $split_url[ $last_pos ] );
		}

		if ( ! $slug ) {
			return false;
		}

		// Check if an anchor (ie. #fragment) is considered external, don't change the URL if we find a match
		$external_anchors = [ \Pressbooks\Interactive\Content::ANCHOR ];
		if ( in_array( $anchor, $external_anchors, true ) ) {
			return false;
		}

		// Cheap cache
		static $lookup = false;
		static $order = false;
		if ( $lookup === false && $order === false ) {
			$lookup = Book::getBookStructure();
			$order = $this->fixOrder( $lookup['__order'] );
		}

		$found = [];
		foreach ( $lookup['__order'] as $post_id => $val ) {
			if (
				$val['post_type'] === $posttype &&
				$val['post_name'] === $slug &&
				$val['export']
			) {
				$found = array_merge( [ 'ID' => $post_id ], $val ); // @codingStandardsIgnoreLine
			}
		}
		if ( empty( $found ) ) {
			return false;
		}

		// Create a new url that points to a file in the epub
		$new_url = '';
		if ( 'part' === $posttype ) {
			// Handle parts
			foreach ( $lookup['part'] as $key => $part ) {
				if ( $part['post_name'] === $slug ) {
					$new_url = 'part-' . sprintf( '%03s', $key + 1 ) . '-' . ( isset( $this->sanitizedSlugs[ $slug ] ) ? $this->sanitizedSlugs[ $slug ] : $slug ) . ".{$this->filext}";
				}
			}
		} else {
			$new_pos = 0;
			foreach ( $order as $post_id => $val ) {
				if ( (string) $val['post_type'] === (string) $found['post_type'] && $val['export'] ) {
					if ( $this->taxonomy->getFrontMatterType( $post_id ) !== 'title-page' ) {
						// Custom title pages aren't numbered.
						++$new_pos;
					}
				}
				if ( (int) $post_id === (int) $found['ID'] ) {
					break;
				}
			}
			if ( $val['post_type'] === 'front-matter' && $this->taxonomy->getFrontMatterType( $post_id ) === 'title-page' ) {
				$new_url = "title-page.{$this->filext}";
			} else {
				$new_url = "{$found['post_type']}-" . sprintf( '%03s', $new_pos ) . '-' . ( isset( $this->sanitizedSlugs[ $slug ] ) ? $this->sanitizedSlugs[ $slug ] : $slug ) . ".{$this->filext}";
			}
		}
		if ( $anchor ) {
			$new_url .= $anchor;
		}

		return $new_url;
	}
13625
public function html($path=null, $pos=0) {
		if($path === null)
			return $this->code;
		return $this->item($path, $pos)->html();
	}
707037
public function setByPosition($pos, $value)
    {
        switch ($pos) {
            case 0:
                $this->setId($value);
                break;
            case 1:
                $this->setTitle($value);
                break;
            case 2:
                $this->setDescription($value);
                break;
            case 3:
                $this->setUrl($value);
                break;
            case 4:
                $this->setThumbUrl($value);
                break;
            case 5:
                $this->setSkillId($value);
                break;
            case 6:
                $this->setPhotographer($value);
                break;
            case 7:
                $this->setPhotographerId($value);
                break;
            case 8:
                $this->setAthlete($value);
                break;
            case 9:
                $this->setAthleteId($value);
                break;
            case 10:
                $this->setUploaderId($value);
                break;
        } // switch()

        return $this;
    }
42787
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getName();
                break;
            case 2:
                return $this->getRole();
                break;
            default:
                return null;
                break;
        } // switch()
    }
33445
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getRemoteAppId();
                break;
            case 2:
                return $this->getApiversion();
                break;
            case 3:
                return $this->getName();
                break;
            case 4:
                return $this->getVersion();
                break;
            case 5:
                return $this->getConfigDisplayerrors();
                break;
            case 6:
                return $this->getConfigBypasscache();
                break;
            case 7:
                return $this->getConfigMinifymarkup();
                break;
            case 8:
                return $this->getConfigDebugmode();
                break;
            case 9:
                return $this->getConfigMaintenancemode();
                break;
            case 10:
                return $this->getConfigGzipscripts();
                break;
            case 11:
                return $this->getConfigRewriteurl();
                break;
            case 12:
                return $this->getConfigAdminemail();
                break;
            case 13:
                return $this->getConfigCachemode();
                break;
            case 14:
                return $this->getStatuscode();
                break;
            case 15:
                return $this->getExtensions();
                break;
            case 16:
                return $this->getLog();
                break;
            case 17:
                return $this->getPHP();
                break;
            case 18:
                return $this->getMySQL();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1259942
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getPersonId();
                break;
            case 2:
                return $this->getFunctionId();
                break;
            case 3:
                return $this->getCreatedAt();
                break;
            case 4:
                return $this->getUpdatedAt();
                break;
            default:
                return null;
                break;
        } // switch()
    }
834106
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getFirstName();
                break;
            case 2:
                return $this->getLastName();
                break;
            case 3:
                return $this->getCreatedAt();
                break;
            case 4:
                return $this->getUpdatedAt();
                break;
            case 5:
                return $this->getVersion();
                break;
            case 6:
                return $this->getVersionCreatedAt();
                break;
            case 7:
                return $this->getVersionCreatedBy();
                break;
            case 8:
                return $this->getPersonTeamLinkIds();
                break;
            case 9:
                return $this->getPersonTeamLinkVersions();
                break;
            case 10:
                return $this->getPersonImageIds();
                break;
            case 11:
                return $this->getPersonImageVersions();
                break;
            case 12:
                return $this->getPersonFunctionLinkIds();
                break;
            case 13:
                return $this->getPersonFunctionLinkVersions();
                break;
            default:
                return null;
                break;
        } // switch()
    }
445089
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getDealerId();
                break;
            case 2:
                return $this->getIsDefault();
                break;
            case 3:
                return $this->getCreatedAt();
                break;
            case 4:
                return $this->getUpdatedAt();
                break;
            case 5:
                return $this->getVersion();
                break;
            case 6:
                return $this->getVersionCreatedAt();
                break;
            case 7:
                return $this->getVersionCreatedBy();
                break;
            case 8:
                return $this->getDealerIdVersion();
                break;
            case 9:
                return $this->getDealerContactInfoIds();
                break;
            case 10:
                return $this->getDealerContactInfoVersions();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1061404
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getAttributeId();
                break;
            case 2:
                return $this->getAttributeTypeId();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1083664
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getCode();
                break;
            case 2:
                return $this->getEn();
                break;
            case 3:
                return $this->getDe();
                break;
            default:
                return null;
                break;
        } // switch()
    }
369740
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getDealerId();
                break;
            case 2:
                return $this->getDay();
                break;
            case 3:
                return $this->getBegin();
                break;
            case 4:
                return $this->getEnd();
                break;
            case 5:
                return $this->getClosed();
                break;
            case 6:
                return $this->getPeriodBegin();
                break;
            case 7:
                return $this->getPeriodEnd();
                break;
            case 8:
                return $this->getCreatedAt();
                break;
            case 9:
                return $this->getUpdatedAt();
                break;
            case 10:
                return $this->getVersion();
                break;
            case 11:
                return $this->getVersionCreatedAt();
                break;
            case 12:
                return $this->getVersionCreatedBy();
                break;
            case 13:
                return $this->getDealerIdVersion();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1110871
public function getValueForPosition($pos) {
        return (isset($this->cells[$pos])) ? $this->cells[$pos]->getValue(): null;
    }
647320
public static function isdigitat($str, $pos)
    {
        if ($pos >= strlen($str))
            return false;

        return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
    }
1091319
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getTitle();
                break;
            case 2:
                return $this->getSlug();
                break;
            case 3:
                return $this->getAthleteLabel();
                break;
            case 4:
                return $this->getObjectSlug();
                break;
            case 5:
                return $this->getObjectLabel();
                break;
            case 6:
                return $this->getObjectPluralLabel();
                break;
            case 7:
                return $this->getSkillSlug();
                break;
            case 8:
                return $this->getSkillLabel();
                break;
            case 9:
                return $this->getSkillPluralLabel();
                break;
            case 10:
                return $this->getSkillPictureUrl();
                break;
            case 11:
                return $this->getGroupSlug();
                break;
            case 12:
                return $this->getGroupLabel();
                break;
            case 13:
                return $this->getGroupPluralLabel();
                break;
            case 14:
                return $this->getTransitionLabel();
                break;
            case 15:
                return $this->getTransitionPluralLabel();
                break;
            case 16:
                return $this->getTransitionsSlug();
                break;
            case 17:
                return $this->getPositionSlug();
                break;
            case 18:
                return $this->getPositionLabel();
                break;
            case 19:
                return $this->getFeatureComposition();
                break;
            case 20:
                return $this->getFeatureTester();
                break;
            case 21:
                return $this->getIsDefault();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1102458
public function parseLinkDestination($str, $pos, $max)
    {
        $lines = 0;
        $start = $pos;
        $result = new \stdClass();
        $result->ok = false;
        $result->pos = 0;
        $result->lines = 0;
        $result->str = '';

        if( $pos === $max ) return $result;

        if ($str[$pos] === '<') {
            $pos++;
            while ($pos < $max) {
                $ch= $str[$pos];
                if ($str[$pos] == "\n" || $this->utils->isSpace($ch)) { return $result; }
                if ($ch === '>') {
                    $result->pos = $pos + 1;
                    $result->str = $this->utils->unescapeAll(substr($str, $start + 1, $pos-($start+1)));
                    $result->ok = true;
                    return $result;
                }
                if ($ch === '\\' && $pos + 1 < $max) {
                    $pos += 2;
                    continue;
                }

                $pos++;
            }

            // no closing '>'
            return $result;
        }

        // this should be ... } else { ... branch

        $level = 0;
        while ($pos < $max) {
            $ch = $str[$pos];

            if ($ch === ' ') { break; }

            // ascii control characters
            $code = ord($ch);
            if ($code < 0x20 || $code === 0x7F) { break; }

            if ($ch === '\\' && $pos + 1 < $max) {
                $pos += 2;
                continue;
            }

            if ($ch === '(' ) {
                $level++;
            }

            if ($ch === ')' ) {
                if ($level === 0) { break; }
                $level--;
            }

            $pos++;
        }

        if ($start === $pos) { return $result; }
        if ($level !== 0) { return $result; }

        $result->str = $this->utils->unescapeAll(substr($str, $start, $pos-$start));
        $result->lines = $lines;
        $result->pos = $pos;
        $result->ok = true;
        return $result;
    }
885545
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getSourceId();
                break;
            case 2:
                return $this->getPageid();
                break;
            case 3:
                return $this->getTitle();
                break;
            case 4:
                return $this->getDisplaytitle();
                break;
            case 5:
                return $this->getPageImageFree();
                break;
            case 6:
                return $this->getWikibaseItem();
                break;
            case 7:
                return $this->getDisambiguation();
                break;
            case 8:
                return $this->getDefaultsort();
                break;
            case 9:
                return $this->getCreatedAt();
                break;
            case 10:
                return $this->getUpdatedAt();
                break;
            default:
                return null;
                break;
        } // switch()
    }
220006
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getTitle();
                break;
            case 2:
                return $this->getDescription();
                break;
            case 3:
                return $this->getUrl();
                break;
            case 4:
                return $this->getThumbUrl();
                break;
            case 5:
                return $this->getSkillId();
                break;
            case 6:
                return $this->getPhotographer();
                break;
            case 7:
                return $this->getPhotographerId();
                break;
            case 8:
                return $this->getAthlete();
                break;
            case 9:
                return $this->getAthleteId();
                break;
            case 10:
                return $this->getUploaderId();
                break;
            default:
                return null;
                break;
        } // switch()
    }