@@ -1516,48 +1516,60 @@ function _convert_css_styles($matches) {
15161516 /**
15171517 * Render an internal media file
15181518 *
1519- * @param string $src media ID
1520- * @param string $title descriptive text
1521- * @param string $align left|center|right
1522- * @param int $width width of media in pixel
1523- * @param int $height height of media in pixel
1524- * @param string $cache cache|recache|nocache
1525- * @param string $linking linkonly|detail|nolink
1519+ * @param string $src media ID
1520+ * @param string $title descriptive text
1521+ * @param string $align left|center|right
1522+ * @param int $width width of media in pixel
1523+ * @param int $height height of media in pixel
1524+ * @param string $cache cache|recache|nocache
1525+ * @param string $linking linkonly|detail|nolink
1526+ * @param bool $returnonly whether to return odt or write to doc attribute
15261527 */
15271528 function internalmedia ($ src , $ title =NULL , $ align =NULL , $ width =NULL ,
1528- $ height =NULL , $ cache =NULL , $ linking =NULL ) {
1529+ $ height =NULL , $ cache =NULL , $ linking =NULL , $ returnonly = false ) {
15291530 global $ ID ;
15301531 resolve_mediaid (getNS ($ ID ),$ src , $ exists );
15311532 list (/* $ext */ ,$ mime ) = mimetype ($ src );
15321533
15331534 if (substr ($ mime ,0 ,5 ) == 'image ' ){
15341535 $ file = mediaFN ($ src );
1535- $ this ->_odtAddImage ($ file , $ width , $ height , $ align , $ title );
1536+ if ($ returnonly ) {
1537+ return $ this ->_odtAddImage ($ file , $ width , $ height , $ align , $ title , true );
1538+ } else {
1539+ $ this ->_odtAddImage ($ file , $ width , $ height , $ align , $ title );
1540+ }
15361541 }else {
15371542/*
15381543 // FIXME build absolute medialink and call externallink()
15391544 $this->code('FIXME internalmedia: '.$src);
15401545*/
15411546 //FIX by EPO/Intersel - create a link to the dokuwiki internal resource
15421547 if (empty ($ title )) {$ title =explode (': ' ,$ src ); $ title =end ($ title );}
1543- $ this ->externalmedia (str_replace ('doku.php?id= ' ,'lib/exe/fetch.php?media= ' ,wl ($ src ,'' ,true )),$ title );
1548+ if ($ returnonly ) {
1549+ return $ this ->externalmedia (str_replace ('doku.php?id= ' ,'lib/exe/fetch.php?media= ' ,wl ($ src ,'' ,true )),$ title ,
1550+ null , null , null , null , null , true );
1551+ } else {
1552+ $ this ->externalmedia (str_replace ('doku.php?id= ' ,'lib/exe/fetch.php?media= ' ,wl ($ src ,'' ,true )),$ title ,
1553+ null , null , null , null , null );
1554+ }
15441555 //End of FIX
15451556 }
15461557 }
15471558
15481559 /**
15491560 * Render an external media file
15501561 *
1551- * @param string $src full media URL
1552- * @param string $title descriptive text
1553- * @param string $align left|center|right
1554- * @param int $width width of media in pixel
1555- * @param int $height height of media in pixel
1556- * @param string $cache cache|recache|nocache
1557- * @param string $linking linkonly|detail|nolink
1562+ * @param string $src full media URL
1563+ * @param string $title descriptive text
1564+ * @param string $align left|center|right
1565+ * @param int $width width of media in pixel
1566+ * @param int $height height of media in pixel
1567+ * @param string $cache cache|recache|nocache
1568+ * @param string $linking linkonly|detail|nolink
1569+ * @param bool $returnonly whether to return odt or write to doc attribute
15581570 */
15591571 function externalmedia ($ src , $ title =NULL , $ align =NULL , $ width =NULL ,
1560- $ height =NULL , $ cache =NULL , $ linking =NULL ) {
1572+ $ height =NULL , $ cache =NULL , $ linking =NULL , $ returnonly = false ) {
15611573 global $ conf ;
15621574 list ($ ext ,$ mime ) = mimetype ($ src );
15631575
@@ -1577,45 +1589,62 @@ function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
15771589 fclose ($ tmp_img );
15781590 }
15791591 }
1580- $ this ->_odtAddImage ($ tmp_name , $ width , $ height , $ align , $ title );
1581- if (file_exists ($ tmp_name )) unlink ($ tmp_name );
1592+ if ($ returnonly ) {
1593+ $ ret = $ this ->_odtAddImage ($ tmp_name , $ width , $ height , $ align , $ title , true );
1594+ if (file_exists ($ tmp_name )) unlink ($ tmp_name );
1595+ return $ ret ;
1596+ } else {
1597+ $ this ->_odtAddImage ($ tmp_name , $ width , $ height , $ align , $ title );
1598+ if (file_exists ($ tmp_name )) unlink ($ tmp_name );
1599+ }
15821600 }else {
1583- $ this ->externallink ($ src ,$ title );
1601+ if ($ returnonly ) {
1602+ return $ this ->externallink ($ src ,$ title ,true );
1603+ } else {
1604+ $ this ->externallink ($ src ,$ title );
1605+ }
15841606 }
15851607 }
15861608
15871609 /**
15881610 * Render a CamelCase link
15891611 *
1590- * @param string $link The link name
1612+ * @param string $link The link name
1613+ * @param bool $returnonly whether to return odt or write to doc attribute
15911614 * @see http://en.wikipedia.org/wiki/CamelCase
15921615 */
1593- function camelcaselink ($ link ) {
1594- $ this ->internallink ($ link ,$ link );
1616+ function camelcaselink ($ link , $ returnonly ) {
1617+ if ($ returnonly ) {
1618+ return $ this ->internallink ($ link ,$ link , null , true );
1619+ } else {
1620+ $ this ->internallink ($ link , $ link );
1621+ }
15951622 }
15961623
15971624 /**
15981625 * @param string $id
15991626 * @param string $name
16001627 */
16011628 function reference ($ id , $ name = NULL ) {
1602- $ this -> doc . = '<text:a xlink:type="simple" xlink:href="# ' .$ id .'" ' ;
1629+ $ ret = '<text:a xlink:type="simple" xlink:href="# ' .$ id .'" ' ;
16031630 if ($ name ) {
1604- $ this -> doc .= '> ' .$ this ->_xmlEntities ($ name ).'</text:a> ' ;
1631+ $ ret .= '> ' .$ this ->_xmlEntities ($ name ).'</text:a> ' ;
16051632 } else {
1606- $ this -> doc .= '/> ' ;
1633+ $ ret .= '/> ' ;
16071634 }
1635+ return $ ret ;
16081636 }
16091637
16101638 /**
16111639 * Render a wiki internal link
16121640 *
1613- * @param string $id page ID to link to. eg. 'wiki:syntax'
1614- * @param string|array $name name for the link, array for media file
1641+ * @param string $id page ID to link to. eg. 'wiki:syntax'
1642+ * @param string|array $name name for the link, array for media file
1643+ * @param bool $returnonly whether to return odt or write to doc attribute
16151644 *
16161645 * @author Andreas Gohr <andi@splitbrain.org>
16171646 */
1618- function internallink ($ id , $ name = NULL ) {
1647+ function internallink ($ id , $ name = NULL , $ returnonly = false ) {
16191648 global $ ID ;
16201649 // default name is based on $id as given
16211650 $ default = $ this ->_simpleTitle ($ id );
@@ -1629,22 +1658,35 @@ function internallink($id, $name = NULL) {
16291658 if ($ hash ) $ url .='# ' .$ hash ;
16301659
16311660 if ($ ID == $ id ) {
1632- $ this ->reference ($ hash , $ name );
1661+ if ($ returnonly ) {
1662+ return $ this ->reference ($ hash , $ name );
1663+ } else {
1664+ $ this ->doc .= $ this ->reference ($ hash , $ name );
1665+ }
16331666 } else {
1634- $ this ->_doLink ($ url ,$ name );
1667+ if ($ returnonly ) {
1668+ return $ this ->_doLink ($ url ,$ name );
1669+ } else {
1670+ $ this ->doc .= $ this ->_doLink ($ url ,$ name );
1671+ }
16351672 }
16361673 }
16371674
16381675 /**
16391676 * Add external link
16401677 *
1641- * @param string $url full URL with scheme
1642- * @param string|array $name name for the link, array for media file
1678+ * @param string $url full URL with scheme
1679+ * @param string|array $name name for the link, array for media file
1680+ * @param bool $returnonly whether to return odt or write to doc attribute
16431681 */
1644- function externallink ($ url , $ name = NULL ) {
1682+ function externallink ($ url , $ name = NULL , $ returnonly = false ) {
16451683 $ name = $ this ->_getLinkTitle ($ name , $ url , $ isImage );
16461684
1647- $ this ->_doLink ($ url ,$ name );
1685+ if ($ returnonly ) {
1686+ return $ this ->_doLink ($ url ,$ name ,$ returnonly );
1687+ } else {
1688+ $ this ->doc .= $ this ->_doLink ($ url ,$ name );
1689+ }
16481690 }
16491691
16501692 /**
@@ -1760,40 +1802,56 @@ function locallink($hash, $name = NULL){
17601802 *
17611803 * You may want to use $this->_resolveInterWiki() here
17621804 *
1763- * @param string $match original link - probably not much use
1764- * @param string|array $name name for the link, array for media file
1765- * @param string $wikiName indentifier (shortcut) for the remote wiki
1766- * @param string $wikiUri the fragment parsed from the original link */
1767- function interwikilink ($ match , $ name = NULL , $ wikiName , $ wikiUri ) {
1805+ * @param string $match original link - probably not much use
1806+ * @param string|array $name name for the link, array for media file
1807+ * @param string $wikiName indentifier (shortcut) for the remote wiki
1808+ * @param string $wikiUri the fragment parsed from the original link
1809+ * @param bool $returnonly whether to return odt or write to doc attribute
1810+ */
1811+ function interwikilink ($ match , $ name = NULL , $ wikiName , $ wikiUri , $ returnonly = false ) {
17681812 $ name = $ this ->_getLinkTitle ($ name , $ wikiUri , $ isImage );
17691813 $ url = $ this -> _resolveInterWiki ($ wikiName ,$ wikiUri );
1770- $ this ->_doLink ($ url ,$ name );
1814+ if ($ returnonly ) {
1815+ return $ this ->_doLink ($ url ,$ name );
1816+ } else {
1817+ $ this ->doc .= $ this ->_doLink ($ url ,$ name );
1818+ }
17711819 }
17721820
17731821 /**
17741822 * Just print WindowsShare links
17751823 *
17761824 * @fixme add image handling
17771825 *
1778- * @param string $url the link
1779- * @param string|array $name name for the link, array for media file
1826+ * @param string $url the link
1827+ * @param string|array $name name for the link, array for media file
1828+ * @param bool $returnonly whether to return odt or write to doc attribute
17801829 */
1781- function windowssharelink ($ url , $ name = NULL ) {
1830+ function windowssharelink ($ url , $ name = NULL , $ returnonly ) {
17821831 $ name = $ this ->_getLinkTitle ($ name , $ url , $ isImage );
1783- $ this ->doc .= $ name ;
1832+ if ($ returnonly ) {
1833+ return $ name ;
1834+ } else {
1835+ $ this ->doc .= $ name ;
1836+ }
17841837 }
17851838
17861839 /**
17871840 * Just print email links
17881841 *
17891842 * @fixme add image handling
17901843 *
1791- * @param string $address Email-Address
1792- * @param string|array $name name for the link, array for media file
1844+ * @param string $address Email-Address
1845+ * @param string|array $name name for the link, array for media file
1846+ * @param bool $returnonly whether to return odt or write to doc attribute
17931847 */
1794- function emaillink ($ address , $ name = NULL ) {
1848+ function emaillink ($ address , $ name = NULL , $ returnonly ) {
17951849 $ name = $ this ->_getLinkTitle ($ name , $ address , $ isImage );
1796- $ this ->_doLink ("mailto: " .$ address ,$ name );
1850+ if ($ returnonly ) {
1851+ return $ this ->_doLink ("mailto: " .$ address ,$ name );
1852+ } else {
1853+ $ this ->doc .= $ this ->_doLink ("mailto: " .$ address ,$ name );
1854+ }
17971855 }
17981856
17991857 /**
@@ -1806,27 +1864,30 @@ function emaillink($address, $name = NULL) {
18061864 */
18071865 function _doLink ($ url ,$ name ){
18081866 $ url = $ this ->_xmlEntities ($ url );
1867+ $ doc = '' ;
18091868 if (is_array ($ name )){
18101869 // Images
1811- if ($ url && !$ this ->disable_links ) $ this -> doc .= '<draw:a xlink:type="simple" xlink:href=" ' .$ url .'"> ' ;
1870+ if ($ url && !$ this ->disable_links ) $ doc .= '<draw:a xlink:type="simple" xlink:href=" ' .$ url .'"> ' ;
18121871
18131872 if ($ name ['type ' ] == 'internalmedia ' ){
1814- $ this ->internalmedia ($ name ['src ' ],
1873+ $ doc .= $ this ->internalmedia ($ name ['src ' ],
18151874 $ name ['title ' ],
18161875 $ name ['align ' ],
18171876 $ name ['width ' ],
18181877 $ name ['height ' ],
18191878 $ name ['cache ' ],
1820- $ name ['linking ' ]);
1879+ $ name ['linking ' ],
1880+ true );
18211881 }
18221882
1823- if ($ url && !$ this ->disable_links ) $ this -> doc .= '</draw:a> ' ;
1883+ if ($ url && !$ this ->disable_links ) $ doc .= '</draw:a> ' ;
18241884 }else {
18251885 // Text
1826- if ($ url && !$ this ->disable_links ) $ this -> doc .= '<text:a xlink:type="simple" xlink:href=" ' .$ url .'"> ' ;
1827- $ this -> doc .= $ name ; // we get the name already XML encoded
1828- if ($ url && !$ this ->disable_links ) $ this -> doc .= '</text:a> ' ;
1886+ if ($ url && !$ this ->disable_links ) $ doc .= '<text:a xlink:type="simple" xlink:href=" ' .$ url .'"> ' ;
1887+ $ doc .= $ name ; // we get the name already XML encoded
1888+ if ($ url && !$ this ->disable_links ) $ doc .= '</text:a> ' ;
18291889 }
1890+ return $ doc ;
18301891 }
18311892
18321893 /**
@@ -2051,8 +2112,10 @@ function _odtAddImageAsFileOnly($src){
20512112 * @param $align
20522113 * @param $title
20532114 * @param $style
2115+ * @param $returnonly
20542116 */
2055- function _odtAddImage ($ src , $ width = NULL , $ height = NULL , $ align = NULL , $ title = NULL , $ style = NULL ){
2117+ function _odtAddImage ($ src , $ width = NULL , $ height = NULL , $ align = NULL , $ title = NULL , $ style = NULL , $ returnonly = false ){
2118+ $ doc = '' ;
20562119 if (file_exists ($ src )) {
20572120 list ($ ext ,$ mime ) = mimetype ($ src );
20582121 $ name = 'Pictures/ ' .md5 ($ src ).'. ' .$ ext ;
@@ -2080,19 +2143,24 @@ function _odtAddImage($src, $width = NULL, $height = NULL, $align = NULL, $title
20802143 }
20812144
20822145 if ($ title ) {
2083- $ this -> doc .= '<draw:frame draw:style-name=" ' .$ style .'" draw:name=" ' .$ this ->_xmlEntities ($ title ).' Legend"
2146+ $ doc .= '<draw:frame draw:style-name=" ' .$ style .'" draw:name=" ' .$ this ->_xmlEntities ($ title ).' Legend"
20842147 text:anchor-type=" ' .$ anchor .'" draw:z-index="0" svg:width=" ' .$ width .'"> ' ;
2085- $ this -> doc .= '<draw:text-box> ' ;
2086- $ this -> doc .= '<text:p text:style-name=" ' .$ this ->styleset ->getStyleName ('legend center ' ).'"> ' ;
2148+ $ doc .= '<draw:text-box> ' ;
2149+ $ doc .= '<text:p text:style-name=" ' .$ this ->styleset ->getStyleName ('legend center ' ).'"> ' ;
20872150 }
2088- $ this -> doc .= '<draw:frame draw:style-name=" ' .$ style .'" draw:name=" ' .$ this ->_xmlEntities ($ title ).'"
2151+ $ doc .= '<draw:frame draw:style-name=" ' .$ style .'" draw:name=" ' .$ this ->_xmlEntities ($ title ).'"
20892152 text:anchor-type=" ' .$ anchor .'" draw:z-index="0"
20902153 svg:width=" ' .$ width .'" svg:height=" ' .$ height .'" > ' ;
2091- $ this -> doc .= '<draw:image xlink:href=" ' .$ this ->_xmlEntities ($ name ).'"
2154+ $ doc .= '<draw:image xlink:href=" ' .$ this ->_xmlEntities ($ name ).'"
20922155 xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> ' ;
2093- $ this -> doc .= '</draw:frame> ' ;
2156+ $ doc .= '</draw:frame> ' ;
20942157 if ($ title ) {
2095- $ this ->doc .= $ this ->_xmlEntities ($ title ).'</text:p></draw:text-box></draw:frame> ' ;
2158+ $ doc .= $ this ->_xmlEntities ($ title ).'</text:p></draw:text-box></draw:frame> ' ;
2159+ }
2160+ if ($ returnonly ) {
2161+ return $ doc ;
2162+ } else {
2163+ $ this ->doc .= $ doc ;
20962164 }
20972165 }
20982166
0 commit comments