Contents

Stellen Sie hier anderen Ihre benutzerdefinierten Tags zur Verfügung

PHP Style Sheet Switcher

Siehe Forum: PHP Style Sheet Switcher

get_template_vars

Wenn Sie in den Modulen mit Smarty-Templates arbeiten, ist es sehr nützlich zu wissen, welche Variablen verfügbar sind und welche Werte sie haben. Glücklicherweise lässt sich dies nun ermitteln:

// gibt eine Liste aller in Smarty zugewiesenen Variablen zurück
// benutzerdefinierter Tag, Name: "get_template_vars"
global $gCms;
$tpl_vars = $gCms->smarty->get_template_vars();
print_r( $tpl_vars );

Autor calguy1000

else_if

Ermittelt den Namen einer Seite und legt in Abhängigkeit dessen fest, was angezeigt werden soll. Nützlich für die Steuerung der Anzeige von Bildern oder der Navigation usw. Nachdem der Name einer Seite ermittelt wurde, kann über die entsprechenden if, elseif und else Aufrufe alles im Template individuell für jede Seite gesteuert werden.

global $gCms;
$thispage = ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "seitenname")  echo "Das ist für die Seite 'seitenname'.";
elseif  ($thispage == "anderername") echo "Das ist für die Seite 'anderername'.";
elseif  ($thispage == "nseiten") echo "Sie können eine beliebige Anzahl von elseif-Klauseln verwenden.";
else echo "Standard-Text";

Autor dan?

recently_updated

Gibt eine Liste mit den 10 zuletzt aktualisierten Seiten aus.

$output = '<div class="nav"><div class="heading">Aktualisierungen</div>';
$output .= '<ul class="links">';
global $gCms;
$hm =& $gCms->GetHierarchyManager();
$db = &$gCms->db;
// gibt eine Liste der 10 zuletzt aktualisierten Seiten aus (außer der Startseite)
$q = "SELECT * FROM ".cms_db_prefix()."content WHERE (type='content' OR type='link')
AND default_content != 1 AND active = 1 AND show_in_menu = 1 
ORDER BY modified_date DESC LIMIT 10";
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
    echo 'Datenbankfehler: '. $db->ErrorMsg()."<br/>";
}
while ($dbresult && $updated_page = $dbresult->FetchRow())
{
    $curnode =& $hm->getNodeById($updated_page['content_id']);
    $curcontent =& $curnode->GetContent();
    $output .= '<li class="updated">';
    $output .= '<a href="'.$curcontent->GetURL().'">'.$updated_page['content_name'].'</a>';
    $output .= '<br />';
    $output .= $updated_page['titleattribute'];
    $output .= '<br />';
    $output .= 'Bearbeitet: ' .$updated_page['modified_date'];
    $output .= '</li>';
}
$output .= '</ul></div>';
echo $output;

author Elijah Lofgren

table_of_contents

Genrates a table of contents for your pages based on the heading tags. It requires each heading tag to have an id like:

<h2 id="packages">Packages</h2>

Put this in a user-defined tag named table_of_contents:

/**
 * Generates a table of contents based on heading tags that have ids
 * @example: <h2 id="packages">Packages</h2>
 */
function get_table_of_contents($page_contents)
{
    // Generate table of contents
preg_match_all("/<h([[:digit:]])[[:space:]]id=\"([a-z-0-9]+)\">(.*)<\/h[0-9]>/i", $page_contents, $match);
    if (FALSE == empty($match[0])) {
        $contents  = "<h2>Contents</h2>\n";
        $contents .= "<ul>\n";
        foreach ($match[0] as $key => $value) {
            if (2 == $match[1][$key]) {
                $contents .= '';
            } else {
                $contents .= '        ';
            }
            $contents .= '<li><a href="'.$_SERVER['REQUEST_URI'].'#'.$match[2][$key].'">'.$match[3][$key].'</a>';
            // Start a new sub-list if this item has children otherwise just end the list item
            if (FALSE == empty($match[1][$key + 1]) && $match[1][$key + 1] == $match[1][$key] + 1) {
                $contents .= "\n    <ul>\n";
                $unclosed_list = TRUE;
            } else {
                $contents .= "</li>\n";
            }
            // If the next item is higher level then close this list item (I.E. current item is h3 and next is h2
            if (FALSE == empty($match[1][$key + 1]) && $match[1][$key + 1] == $match[1][$key] - 1) {
                $contents .= "    </ul>\n</li>\n";
                $unclosed_list = FALSE;
            }
        }
        if (FALSE == empty($unclosed_list)) {
            $contents .= "    </ul>\n</li>\n";
        }
        $contents .= "</ul>\n";
    } else {
        $contents = '';
    }
    return $contents;
}
echo get_table_of_contents($params['thepagecontent']);

Then in your template put this:

{content assign=pagecontent}
{table_of_contents thepagecontent="$pagecontent"}

author Elijah Lofgren

embed existing smarty app

I need to show existing data from an app that was written with smarty and had existing templates this seems to work for me at least

made a function in plugins

<?php
function smarty_cms_function_myapp($params, &$smarty){
$smarty->assign('comments','big comment');

//both these methods work
$smarty->display('myapp.tpl');
or
return $smarty->fetch('myapp.tpl');
// just chose one method I think 
//fetch would be best
}
?>

the tpl file had existing smarty stuff and was placed in tmp/templates eg myapp.tpl

{$smarty.now|date_format}smarty now
<br />
it works
<br />
{$comments}

and in your page {myapp} I also found like {$comments} also works

author cdstg


change copyright date based on server

make a user defined tag eg custom_copyright

//set start to date your site was published
$startCopyRight='2005';
if(date('Y')== $startCopyRight){
    echo $startCopyRight;
}else{
    echo $startCopyRight.' - '. date('Y');
}

in the Global Content Blocks place {custom_copyright} in the footer now next year it will say 2005 - 2007

author cdstg

listpictures

global $gCms;
$dir = $gCms->config['root_path'] . DIRECTORY_SEPARATOR .'uploads/images/africa/';
$url = './uploads/images/africa/';
echo '<ul>';
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
	if ($dh = opendir($dir)) {
		while (($file = readdir($dh)) !== false) {
                     if ('file' == filetype($dir . $file)) {
echo "<li><a href=".$url.$file.'" rel="lightbox"><img src="'.$url.'thumb_'.$file.'" /></a>'."</li>\n";	
                    }
       }
       closedir($dh);
   }
}
echo '</ul>';

Author: Elijah Lofgren

count_news_items

Create a new User Defined Tag named 'count_news_items' with the following content:

global $gCms;
$items = $gCms->smarty->get_template_vars('items');
$gCms->smarty->assign('itemcount', count($items));

Then put something like this in your news summary template:

<!-- Start News Display Template -->
{count_news_items}
{if $itemcount != 0}
{foreach from=$items item=entry}
...
{/foreach}
{else}
No items
{/if}
<!-- End News Display Template -->

Author: Elijah Lofgren

Simple, accessible Wikipedia-style external links

This article on Max Design was the inspiration for this tag, which appends the text " (external link)" to the link text of your link. When viewed in a CSS-enabled browser this phrase is hidden from view and replaced with a graphical icon indicating an external link.

Note: Internet Explorer does not display the icon correctly when link text spans multiple lines so non-breaking spaces are inserted between words to overcome this problem.

Using CSS this icon will change color to reflect the following link states:

  •  :link
  •  :visited
  •  :hover

Create a new user-defined tag named 'extlink' with the following content:

$linktext = $params['linktext'];
$words = explode(" ", $linktext);
if ($words != $linktext) {
  $linktext = $words[0];
  foreach ($words as $key => $value) {
    if ($key >0) {
      $linktext .= ' '.$value;
    }
  }
}
echo '<a class="external" href="'.$params['href'].'"';
if(!empty($params['title']))
	echo ' title="'.$params['title'].'"';
echo '>'.$linktext.'<span> (external link)</span></a>';

This tag accepts three parameters:

  • href—contains the href for the external link (required).
  • linktext—contains the linktext to be inserted into the link (required).
  • title—contains the title attribute text to be inserted into the link (;optional).


Example:

{extlink href="http://external.site.com" title="A site about widgets" linktext="Cool Widgets"}

will generate the following HTML:

<a class="external" href="http://external.site.com" title="A site about widgets">Cool&nbsp;Widgets<span> (external link)</span></a>

Right click and save as "External.gif"

Right click on the image above and save it to your computer as "External.gif", then upload it to the location on your web site where you store your images.

The following stylesheet rules will need to be added to your CSS to implement this functionality

a.external span {
  position: absolute;
  left: -5000px;
  width: 4000px;
}
a.external {
  padding: 0 12px 0 0
}
a.external:link {
  background: url(/images/External.gif) no-repeat 100% 0;
}
a.external:visited {
  color: #609;
  background: url(/images/External.gif) no-repeat 100% -100px;
}
a.external:hover {
  color: #f00;
  background: url(/images/External.gif) no-repeat 100% -200px;
}

If your web site image folder is not "/images/" you will need to modify the rules above to point to the correct location for the image file "External.gif".

Author: Tygger2512

acronym_replacer

Automatically replaces acronyms in your content with an <acronym title="description">TLA</acronym> tag, unless you surround the acronym with $ signs--e.g. DVD will be replaced with <acronym title="Digital Versatile Disc">DVD</acronym> but $DVD$ will be replaced with DVD.

This is a modified version of the Acronym Replacer 2.0 WordPress Plugin.

Put this in a user-defined tag named acronym_replacer:

/*
Acronym Replacer is modified from the Acronym Replacer 2.0
WordPress Plugin at: http://www.huddledmasses.org/wp-content/plugins/source.php?file=acronyms.php
----------------------------------------------------------
replace the following line in your template:

{content}

with:

{content assign=pagecontent}
{acronym_replacer thepagecontent="$pagecontent"}

*/

$text = $params['thepagecontent'];
global $acronym_acronym;
// First, define all the things to replace, without using parenthesis or pipes (|).
// Each definition is in the form: // "acronym" => "definition",
// ESPECIALLY note that they all end with commas EXCEPT the last one.

if( empty($acronym_acronym) ) {
   $acronym_acronym = array(
      "AOL" => "America Online",
      "API" => "Application Programming Interface",
      "BTW" => "By The Way",
      "BPL" => "Broadband over Power Lines",
      "CD" => "Compact Disc",
      "CGI" => "Common Gateway Interface",
      "CLI" => "Common Language Interpreter",
      "CMS" => "Content Management System",
      "CSS" => "Cascading Style Sheet",
      "CVS" => "Concurrent Versions System",
      "DNS" => "Domain Name System",
      "DOM" => "Document Object Model",
      "DSL" => "Digital Subscriber Line (broadband over phone lines)",
      "DTD" => "Document Type Definition",
      "DVD" => "Digital Versatile Disc",
      "EFT" => "Emotional Freedom Technique",
      "FAQ" => "Frequently Asked Questions",
      "FCC" => "Federal Communications Commission",
      "FOAF" => "Friend Of A Friend is a RDF dialect for describing relationships",
      "FSF" => "Free Software Foundation",
      "FTP" => "File Transfer Protocol",
      "FTTH" => "Fiber to the Home",
      "GB" => "Gigabyte",
      "GFDL" => "GNU Free Documentation License",
      "GPG" => "Gnu PG (Open source public key encryption)",
      "GPL" => "GNU General Public License",
      "GTK" => "GUI ToolKit - The GIMP Tool Kit for dcreating user-interfaces",
      "GUI" => "Graphical User Interface",
      "HDTV" => "High Definition TeleVision",
      "HTML" => "HyperText Markup Language",
      "HTTP" => "HyperText Transfer Protocol",
      "IE" => "Internet Explorer",
      "ICANN" => "Internet Corporation for Assigned Names and Numbers",
      "IHOP" => "International House of Pancakes",
      "IIRC" => "if I remember correctly",
      "IIS" => "Internet Infomation Server",
      "IM" => "Instant Message",
      "IMAP" => "Internet Message Access Protocol",
      "IP" => "Internet Protocol",
      "IRC" => "Internet Relay Chat - like Instant Messaging for groups",
      "JSP" => "Java Server Pages",
      "KB" => "Kilobyte",
      "KDE" => "K Desktop Environment",
      "KVM" => "Keyboard, Video, Mouse switch for controlling multiple computers",
      "LDAP" => "Lightweight Directory Access Protocol",
      "LGPL" => "GNU Lesser General Public License",
      "MAPI" => "Mail Application Programming Interface",
      "MB" => "Megabyte",
      "MP3" => "MPEG Layer 3 - a common audio codec for music files",
      "MS" => "Microsoft",
      "MSDN" => "Microsoft Developer Network",
      "MSIE" => "Microsoft Internet Explorer",
      "MSN" => "Microsoft Network",
      "NNTP" => "Network News Transfer Protocol - the protocol used for NewsGroups",
      "NYC" => "New York City",
      "OPML" => "Outline Processor Markup Language",
      "P2P" => "Peer To Peer",
      "PBS" => "Public Broadcasting System",
      "PDF" => "Portable Document Format",
      "PGP" => "Pretty Good Privacy (public key encryption)",
      "PHP" => "Hypertext PreProcessing",
      "PNG" => "Portable Network Graphics",
      "POP" => "Short for POP3, the Post Office Protocol for email",
      "POP3" => "Post Office Protocol 3 (for email)",
      "RAID" => "Redundant Array of Independent Disks",
      "RDF" => "Resource Description Framework",
      "RPC" => "Remote Procedure Call",
      "RSS" => "Really Simple Syndication",
      "SIG" => "Special Interest Group",
      "SOAP" => "Simple Object Access Protocol",
      "SQL" => "Structured Query Language (a database standard)",
      "SSH" => "Secure SHell (encrypted protocol replaces telnet and FTP)",
      "SSN" => "Social Security Number",
      "SSL" => "Secure Sockets Layer (a security protocol)",
      "SVG" => "Scalable Vector Graphics",
      "TCP" => "Transmission Control Protocol",
      "UDP" => "User Datagram Protocol",
      "URI" => "Uniform Resource Identifier",
      "URL" => "Uniform Resource Locator",
      "USB" => "Universal Serial Bus",
      "VB" => "Visual Basic",
      "VBS" => "Visual Basic Script",
      "VM" => "Virtual Machine",
      "VNC" => "Virtual Network Computing",
      "W3C" => "World Wide Web Consortium",
      "WCAG" => "Web Content Accessibility Guidelines",
      "WYSIWYG" => "what you see is what you get",
      "XHTML" => "eXtensible HyperText Markup Language - HTML reformulated as XML",
      "XML" => "eXtensible Markup Language",
      "XSL" => "eXtensible Stylesheet Language",
      "XSLT" => "eXtensible Stylesheet Language Transformation"
      );
   }
   foreach($acronym_acronym as $acronym => $description) {

      $text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$acronym\b(?!:)(?![^<>]*?>)|imsU","<acronym title=\"$description\">$acronym</acronym>" , $text);
     
      // Acronyms wrapped in dollar signs will just be unwrapped: 
      // So: $AOL$ will become AOL, without the <acronym title="America Online">AOL</acronym> 
      $text = preg_replace("|[$]<acronym title=\"$description\">$acronym</acronym>[$]|imsU" , "$acronym" , $text);
   }
return trim( $text );

Then in your template put this:

{content assign=pagecontent}
{acronym_replacer thepagecontent="$pagecontent"}

Author: Tygger2512

style_switcher

Note: Images used are the ones used here: http://test.thinkofdesign.com/Default.aspx?alias=test.thinkofdesign.com/beyondcss

Create new UDT named 'style_switcher' with this content:

if ('css_head' == $params['action']) {
if (FALSE != isset($_COOKIE['Style_Layout']) && 'small' != $_COOKIE['Style_Layout']) {
echo '<link rel="stylesheet" type="text/css" href="stylesheet.php?name='.$params['template'].'_layout_'.$_COOKIE['Style_Layout'].'" />';
}
if (FALSE != isset($_COOKIE['Style_Text'])  && 'small' != $_COOKIE['Style_Text']) {
echo '<link rel="stylesheet" type="text/css" href="stylesheet.php?name='.$params['template'].'_text_'.$_COOKIE['Style_Text'].'" />';
}
}
if ('show_switcher' == $params['action']) {
echo <<<EOF
			  <script type="text/javascript">function setLayout(size){ document.cookie = 'Style_Layout=' + escape(size) + ';expires=' + new Date('December 31, 2020 23:59:59').toGMTString() + ';path=/';location.reload();}</script>
<span style="margin-right: 1em;">
EOF;
if (FALSE != isset($_COOKIE['Style_Layout']) && 'small' != $_COOKIE['Style_Layout']) {
echo '<a href="javascript:setLayout(\'small\')">';
}
echo '<img alt="Narrow width layout" src="uploads/images/style_switcher/icon-layout-small';

if (FALSE == isset($_COOKIE['Style_Layout']) || 'small' == $_COOKIE['Style_Layout']) {
echo '-on';
}
echo '.gif" style="height:17px;width:16px;" />';
if (FALSE != isset($_COOKIE['Style_Layout']) && 'small' != $_COOKIE['Style_Layout']) {
echo '</a>';
}
if ('medium' != $_COOKIE['Style_Layout']) {
  echo '<a href="javascript:setLayout(\'medium\')">';
}
echo '<img alt="Medium width layout" src="uploads/images/style_switcher/icon-layout-medium';
if (FALSE != isset($_COOKIE['Style_Layout']) && 'medium' == $_COOKIE['Style_Layout']) {
echo '-on';
}
echo '.gif" style="height:17px;width:16px;" />';
if ('medium' != $_COOKIE['Style_Layout']) {
echo '</a>';
}
if ('large' != $_COOKIE['Style_Layout']) {
echo '<a href="javascript:setLayout(\'large\')">';
}
echo '<img alt="Large width layout" src="uploads/images/style_switcher/icon-layout-large';
if (FALSE != isset($_COOKIE['Style_Layout']) && 'large' == $_COOKIE['Style_Layout']) {
echo '-on';
}
echo '.gif" style="height:17px;width:16px;" />';
if ('large' != $_COOKIE['Style_Layout']) {
echo '</a>';
}
echo '</span>';
echo "<script type=\"text/javascript\">function setText(size){ document.cookie = 'Style_Text=' + escape(size) + ';expires=' + new Date('December 31, 2020 23:59:59').toGMTString() + ';path=/';location.reload();}</script>";

if (FALSE != isset($_COOKIE['Style_Text']) && 'small' != $_COOKIE['Style_Text']) {
    echo '<a href="javascript:setText(\'small\')">';
}
echo '<img alt="Small text" src="uploads/images/style_switcher/icon-text-small';
if (FALSE == isset($_COOKIE['Style_Text']) || 'small' == $_COOKIE['Style_Text']) {
echo '-on';
}
echo '.gif" style="height:17px;width:17px;" />';
if (FALSE != isset($_COOKIE['Style_Text']) && 'small' != $_COOKIE['Style_Text']) {
echo '</a>';
}
if ('medium' != $_COOKIE['Style_Text']) {
echo '<a href="javascript:setText(\'medium\')">';
}
echo '<img alt="Medium text"  src="uploads/images/style_switcher/icon-text-medium';
if (FALSE != isset($_COOKIE['Style_Text']) && 'medium' == $_COOKIE['Style_Text']) {
echo '-on';
}
echo '.gif" style="height:17px;width:17px;" />';
if ('medium' != $_COOKIE['Style_Text']) {
echo '</a>';
}
if ('large' != $_COOKIE['Style_Text']) {
echo '<a href="javascript:setText(\'large\')">';
}
echo '<img alt="Large text"  src="uploads/images/style_switcher/icon-text-large';
if (FALSE != isset($_COOKIE['Style_Text']) && 'large' == $_COOKIE['Style_Text']) {
echo '-on';
}
echo '.gif" style="height:17px;width:17px;" />';
if ('large' != $_COOKIE['Style_Text']) {
echo '</a>';
}
}

Then in betwen your 'head' tags in your template put something like this:

{style_switcher action="css_head" template="business_design"}

Next, where you want the switcher to appear put this:

Style: {style_switcher action="show_switcher"}

Now, create stylesheets with names like these:

  • business_design_layout_large
  • business_design_layout_medium
  • business_design_text_large
  • business_design_text_medium

Author: Elijah Lofgren


favicon

This tag generates XHTML code to display a favicon in the browser. To generate a icon you can use this http://www.html-kit.com/favicon/.

Create a new User Defined Tag named 'favicon' with the following content:

if(isset($params['static']))
   echo '<link rel="shortcut icon" href="'.$params['static'].'" type="image/x-icon" />'."\n";

if(isset($params['animated']))
   echo '<link rel="icon" href="'.$params['animated'].'" type="image/gif" />'."\n";

Then put something like this in the header of your template:

<!--Favicon-->
{favicon static="../images/favicon.ico" animated="../images/animated_favicon.gif"}

The two attributes are optional, but if you leave them both there isn't happening nothing.

Author: Christophe Lambrechts (EhpotsirhC)

Google adsense

get your adsense code from google.

copy paste it as is into user defined tag (in extension -> user defined tags -> add user defined tag) as this code has javascript { and } we need to wrap it inside {literal} and {/literal} otherwise smarty will miss interperet those extra { } as its own. so add {literal} at the top and {/literal} at the bottom.

edit your template in which you want the ads to be shown. check where you want your ads (you might want to wrap em in
<div id="ads"> </div>
) and add call to your user defined tag with {name_of_your_udt}. save

refresh your page, and thats it.

Author: tsw


If the {literal} tags do not work or you are unable to generate a "user defined tag" use the following php.

1. Get your Google Adsense code.

2. In the top menu bar locate extensions -> user defined tags then click on add user defined tag.

3. In the name box type google_ads

4. Type this in the code box...

echo $ads='<paste the google adsense script here>';

Open the template file that you are using for your site and insert {google_ads} (which is the same as the name that was typed in step 3) where you want the ads to appear.

Author: Paul C

Get a page's root parent's alias

Gets the alias of a pages very top parent.

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_alias';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Alias();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

Create a new user-defined tag called get_root_page_alias and copy in the above code.

The tag can be called using...

{get_root_page_alias assign="varname"}

An example use would be...

{get_root_page_alias assign="root_page_alias"} The root parent of this page is:{$root_page_alias}

Author: calguy1000 (posted by binarybee on the forum).

Get a page's root parent's hierarchy-position

Gets the hierarchy-position of a pages very top parent.

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_id';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Hierarchy();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

Create a new user-defined tag called get_root_page_hierarchy and copy in the above code.

The tag can be called using...

{get_root_page_hierarchy assign="varname"}

An example use would be...

{get_root_page_alias hierarchy="root_page_hierarchy"} The root parent hierarchy of this page is:{$root_page_hierarchy}

Author: calguy1000 (modified by nils73 and posted on the forum).

File link

Description: Use this tag for linking files within your page. The link is furthermore also provided with the filesize of the file you are linking.

The tag is represented similar to

Description of the file (2.56MB)

How to use it: Add the following code as a new User Defined Tag. Name it e.g. 'filelink'.

// ----
// filelink - user defined tag for cms made simple
// Author: Kutschera Ralph
// Email: news2006@ecuapac.dyn.priv.at
// Last Update: 09/26/2006
// No warranty.
// ----

// get file
$localprefix='/var/www/pathtocms/uploads/File/'; // server sided root directory of the files you are linking
$webprefix='uploads/File/'; // the same directory but where your webserver will find it

$localpathtofile=$localprefix.$params['file'];
$webpathtofile=$webprefix.$params['file'];

// get link name
$linkname='';
if(isset($params['name'])) {
  $linkname = $params['name'];
}
else {
  // you can leave away the tag attribute 'name'
  // if so, the name of the file is shown as the link
  $linkname = basename($localpathtofile);
}

// check if file exists
if(file_exists($localpathtofile)) {
  $filesize = filesize($localpathtofile);

  // beautify filesize
  $suffix = "B"; // for Bytes
  if($filesize > 1024) {
    $filesize = $filesize / 1024;
    $suffix = "KB";

    if($filesize > 1024) {
      $filesize = $filesize / 1024;
      $suffix = "MB";

      if($filesize > 1024) {
        $filesize = $filesize / 1024;
        $suffix = "GB";
      }
    }
  }

  $filesize = sprintf("%.2f", $filesize);

  // edit the following line, if you want a different representation of your link
  echo '<a href="'.$webpathtofile.'"><b>'.$linkname.'</b> ('.$filesize.$suffix.')</a>';
}
else {
  // this is shown if the file you try to link to cannot be find
  echo $linkname.' (sorry, broken)';
}

Now if you want to provide a link to a file of your page, simply add

{filelink file='path/to/file' name='Name shown as the link or description of file'}

and you get a link as shown in the description. In the example above the file is saved at /var/www/pathtocms/uploads/File/path/to/file on your server. As you will use another server environment than I do, you'll have to edit the variables $localprefix and $webprefix in the above code. I think, the code should be self explanatory. You can omit the tag attribute 'name' if you want the name of the file as the link text. The code also checks whether the file does exist and gives a '(sorry, broken)' otherwise.


User submitted plugins

Geshi hilight

download geshi and unzip it in your plugins folder (refer to geshi documentation on geshis cabapilities geshi doc)

Create new file in the lib/smarty/plugins dircctory named "block.cms_geshi.php" with this content

  <?php
  include_once(dirname(__FILE__) .'/geshi/geshi.php');
  /***
   * GeSHi highlighting
   * -------------------------------------------------------------
   * File:     block.highlight.php
   * Type:     block
   * Name:     highlight
   * Purpose:  highlight a block of text using GeSHi
   * Author:   tsw
   * -------------------------------------------------------------
   */
  function smarty_block_cms_geshi($params, $content, &$smarty)
  {
    if (isset($content) && isset($params['lang'])) {
      return geshi_highlight("<pre>".$content."</pre>", $params['lang'], "", true);
    }
  }
  ?>

now you can have hilighted code with calling this block from your page with

  {cms_geshi lang="php"}
  <?php echo 1; ?>
  {/cms_geshi}

Note: CMSMS cant take responsibility for these codes please read through the code before using. All tags shared under GPL license
This page in: English - Deutsch - Español - Français - Italiano - Lietuvių - Nederlands - Norsk - Polski - Česky - Русский - Svenska - Tiếng Việt - عربي - 日本語 简体中文

Share your tags here/de

From CMSMS

Arvixe - A CMSMS Partner