Support » Plugin: Mendeley Plugin » Custom CSL in 1.1.18

  • Resolved poundsixzeros

    (@poundsixzeros)


    Sorry to bug you again but my previous post was marked resolved but I’m still having issues.
    I installed the new version, cleared cache (browser and plugin) and retrieved a new access token from Mendeley. Unfortunately it isn’t working with a local csl or an external one.

    I pasted the old code from the forum post into the new formatDocument function and it works again. Could it be that my CURL server settings mess it up with the new code? If so, what should the CURL settings be?
    Also, I am running php7.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author kochm

    (@kochm)

    Could you please post the code you pasted into the source code here so I can check?

    Thread Starter poundsixzeros

    (@poundsixzeros)

    Here you go:

    function formatDocument($doc, $csl=Null, $textonly=False, $showcover=False, $showlink=False) {
    			$result = '';
    
                            // format document with a given CSL style and the CiteProc.php
                            if ($csl != Null && class_exists("citeproc")){
                            	// read the given CSL style from XML document, load it to a string, and convert it to an object
    				$cacheid = "csl-".$csl;
    				$csl_file = $this->getOutputFromCache($cacheid);
    				if (empty($csl_file)) {
    				        $curl = curl_init($csl);
    					curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    					
    					$http_headers = array(
    						'User-Agent: Junk', // Any User-Agent will do here
    					);
    					curl_setopt($curl, CURLOPT_HEADER, true);
    					curl_setopt($curl, CURLOPT_HTTPHEADER, $http_headers);
    					
                            		$csl_file = curl_exec($curl);
    					if (curl_getinfo($curl,CURLINFO_HTTP_CODE) < 400) {
    					   if ($csl_file !== false) {
    					      $pos_body = stripos($csl_file, "<?xml version");
    					      $csl_file = substr($csl_file, $pos_body);
    					      $this->updateOutputInCache($cacheid, $csl_file);
    					   } else {
    					      echo "<p>1 Mendeley Plugin Error: Failed accessing Menedley API: " . curl_error($curl) . "</p>";
    					   }
    					} else {
    					   echo "<p>2 Mendeley Plugin Error: Failed accessing Mendeley API: " . curl_getinfo($curl,CURLINFO_HTTP_CODE) . "||||" . $csl_file . "</p>";
    					   $csl_file = "";
    					}
    					curl_close($curl);
    				}
                            	$csl_object = simplexml_load_string($csl_file);
    Plugin Author kochm

    (@kochm)

    Thanks! I included the additional code fragments in the plugins source code, tested everything and released a new version with the code.

    Thread Starter poundsixzeros

    (@poundsixzeros)

    It works! Thanks @kochm!

    BTW, please credit @dinel2016 for the code. I just passed it along.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom CSL in 1.1.18’ is closed to new replies.