WordPress.org

Ready to get started?Download WordPress

Forums

teachPress
Export of links to BibTex format (1 post)

  1. jfbertrand
    Member
    Posted 10 months ago #

    Hi,

    I like your plugin, very well done - thanks
    here's a useful piece of code for anyone wanting to migrate there WP-links to TeachPress ...

    Visit
    JFBertrand.ca
    for the install WP shortcode

    OR

    Here's the code for the ones that can implement it themselves, there is some parsing in there for my own usage but you get the idea... create a file called wp-links-bibtex.php in you wp root ... then load it from the front end - it will creat a .txt file with the re-formated linkks to bibtex.

    <?php
    /**
     * Outputs the BibTex format from the OPML XML format for getting the links defined in the link
     * administration. This can be used to export links from one blog over to
     * TeachPress or any other BibTex manager. Links aren't exported by the WordPress export, so this file handles
     * that.
     *
     * This file is not added by default to WordPress theme pages when outputting
     * feed links. It will have to be added manually for browsers and users to pick
     * up that this file exists.
     *
     * @package WordPress
     */
    
    require_once('./wp-load.php');
    
    header('Content-Type: text/txt; charset=' . get_option('blog_charset'), true);
    $link_cat = '';
    if ( !empty($_GET['link_cat']) ) {
    	$link_cat = $_GET['link_cat'];
    	if ( !in_array($link_cat, array('all', '0')) )
    		$link_cat = absint( (string)urldecode($link_cat) );
    }
    
    if ( empty($link_cat) )
    	$cats = get_categories(array('taxonomy' => 'link_category', 'hierarchical' => 0));
    else
    	$cats = get_categories(array('taxonomy' => 'link_category', 'hierarchical' => 0, 'include' => $link_cat));
    
    $myCounterA = 2000;
    foreach ( (array)$cats as $cat ) :
    	$catname = apply_filters('link_category', $cat->name);
    
    	$bookmarks = get_bookmarks(array("category" => $cat->term_id));
    	//print_r($bookmarks);
    	//exit;
    	$myCounterB = 0;
    	foreach ( (array)$bookmarks as $bookmark ) :
    		$title = apply_filters('link_title', $bookmark->link_name);
    		$description = apply_filters('link_title', $bookmark->link_description);
    		$arr = explode(' ', $bookmark->link_updated);
    		$date = $arr[0];
    		$is_university = "";
    		$is_protocol = "";
    		$is_link = "";
    
    		//$cleanTitle = ord($title);
    		$cleanTitle = $title;
    		if ( strpos($description, "Protocol") !== false || strpos($description, "protocol") !== false || strpos($description, "Procedure") || strpos($description, "procedure") || strpos($description, "description") || strpos($description, "technique") ) {
    			$is_protocol = "Protocol, ";
    			$title = $cleanTitle;
      	} else if ( is_numeric($cleanTitle[0]) && $cleanTitle[1] != "-") {
      		$title = str_replace(". ", "", strstr($cleanTitle, "."));
    			$title = str_replace(".", "", $title);
      		$is_university = "university, ";
    		} else {
    			$is_link = "link, ";
    			$title = $cleanTitle;
    		}
    
    ?>
    @misc{sc-<?php echo $myCounterA ."-". $myCounterB; ?>, title = {<?php echo $title;?>}, url = {<?php echo esc_attr($bookmark->link_url); ?>}, date = {<?php echo $date; ?>}, abstract = {<?php echo $description; ?>}, keywords = {<?php echo $is_university . $is_protocol . $is_link; ?> <?php echo $catname; ?>}}
    <?php
    	//echo "\n";
    	$myCounterB++;
    	endforeach; // $bookmarks
    
    //echo "\n";
    $myCounterA++;
    endforeach; // $cats
    ?>

    http://wordpress.org/extend/plugins/teachpress/

Reply

You must log in to post.

About this Plugin

About this Topic