Projects/kde.org/Capacity HOWTO: Difference between revisions

    From KDE TechBase
    No edit summary
     
    (20 intermediate revisions by 11 users not shown)
    Line 1: Line 1:
    __TOC__
    {{ Moved To Community | KDE.org/Capacity HOWTO}}
     
    ==Introduction==
     
    Capacity is a versatile framework which helps you to construct
    your page by focusing on the content. Your pages will be simple
    PHP-files which include predefined header and footer. This header/footer
    layout the page, you only provide the real content and menu structure.
     
     
    ==Example PHP-file==
     
    Any normal page just contains:
     
      <?php
        $page_title = "Page Title";
        include "header.inc";
      ?>;
     
      Content of the web page
     
      <?php include "footer.inc"; ?>
     
    ==The magic site.inc==
    For each subsite, a {{path|site.inc}} in the toplevel directory of this page,
    which would be equal to the later documentroot on the server in many
    cases, may be created. This include is used by the {{path|header.inc}}, it
    should contain some information about your site, like it's name
    and the email address of the webmaster, this will be used by header/footer
    to setup the page correct.
     
    An example {{path|site.inc}} would be:
     
      <?php
        // promote which subdomain we are
        // we are www.kde.org in this case!
        $site = "www";
     
        // use new style ;) yeah
        $templatepath = "newlayout/";
     
        // promote title to use
        $site_title = i18n_var("K Desktop Environment");
     
        // links in the top bar, right
        $menuright = array ('family/'=>'Sitemap',
          'contact/'=>'Contact Us');
      ?>
     
    Even in the {{path|site.inc}} you can already use the i18n-functions,
    which is important to have the names right on translated pages!
     
    ==Global Variables setup by header.inc==
    The {{path|header.inc}} does some setup of global vars, even before it includes the {{path|site.inc}}, these are:
     
      $site_root
      $document_root
      $url_root
      $current_relativeurl
     
    * <code>$site_root</code> contains the relative path to the toplevel of the current site, like:
      $site_root = "../.."
     
    * <code>$document_root</code> contains the absolute pathname which is the documentroot of this site, even correct if the site isn't in it's own vhost. Example:
      $document_root = "/home/www/sites/www"
     
    * <code>$url_root</code> contains the absolute base url to the toplevel of your site, if your site would, for example, have a it's toplevel in http://127.0.0.1:8080/sites/www, like it is for staging, this would contain:
      $url_root = /sites/www
     
    * <code>$current_relativeurl</code> contains the relative part of the current url to the url_root, would you access http://127.0.0.1:8080/sites/www/whatiskde/manifest.php and /sites/www is the <code>$url_root</code>, it would contain
      $current_relativeurl = whatiskde/manifest.php
     
    '''BE AWARE:''' In former version of the framework it was common to set the <code>$site_root</code> manually before including the {{path|header.inc}}, this won't work now, as the {{path|header.inc}} will overwrite the <code>$site_root</code>. This should cause no danger, as {{path|header.inc}} should find out the right one, but in the long term, all manual definitions should be removed, the global variables {{path|header.inc}} exports should be used to replace the usage of the old <code>$site_root</code>.
     
    The framework is clever, it will never add trailing slashs to the <code>$site_root</code>, <code>$document_root</code> and <code>$url_root</code>, therefor they can and must always be used like:
      $some_url = "$site_root/mycoolpage.php"
     
    ==Configuration Variables==
     
    You can set some variables to alter the behaviour of the framework, either global in your site.inc or in front of your {{path|header.inc}} inclusion in each .php-files.
     
    Useful variables are:
     
    * The Name for your whole subdomain/site, best set once in {{path|site.inc}}
      $site_title = "KDE Foo Site Title";
     
    * The title of the individual page.
      $page_title = "Page Title";
     
    * Don't show edit function on the page. The default is <code>$showedit = true;</code>. This setting should normally not be used. {{path|site.inc}} is the preferred place.
     
      $showedit = false;
     
    ==Online Editing==
     
    Capacity features online editing and previewing of changes.
     
    You can make and preview changes of existing pages online by clicking on the [edit] link at the bottom of each page. Try it on [http://www.kde.org/index.php?edit this page].
    Then you can download you changes and commit them yourself via SVN, or you can click the link to email a unified diff to the web team.
     
    ==Menu Definitions==
     
    The navigation menu is defined by a number of menu.inc files.
    They are included by a function in media/includes/classes/class_menu.inc, which is called from media/includes/header.inc.
    The general menu structure is defined in the menu.inc file of the root directory of each KDE subsite (e.g. http://www.kde.org/menu.inc or http://www.kde.org/areas/kde-ev/menu.inc).
     
    It should look like this:
      <?php
        $this->setName ("KDE Foo Site Title");
        $section =&amp; $this->appendSection("Inform");
        $section->appendLink("Home","");
        $section->appendLink("KDE Home","http://www.kde.org/",false);
       
        $section =&amp; $this->appendSection("A Second Menu Section");
        $section->appendDir("A Subdirectory","subdirectory");
        $section->appendLink("A Single Page","singlepage.php");
      ?> 
     
    Each mentioned subdirectory will then also be searched for a menu.inc file to define a submenu (e.g. http://www.kde.org/whatiskde/menu.inc).
     
    The format is similar:
      <?php
        $this->appendDir("A Subsubdirectory","subsubdirectory");
        $this->appendLink("A Page in the Subdirectory","singlepage.php");
      ?>
     
    The content of subsubdirectories is currently not added to the menu, but this may change in future.
    If a subdirectory has just the index.php file or a submenu for the subdirectory is not desired, then an empty menu.inc can be added. If the menu.inc is missing, then the subdirectory is be treated like having an empty menu.inc file.
     
    ==Headlines==
     
    The main headline of a page is defined via <code>$page_title</code>.
    If a page has several sections with a headline each, &lt;h2&gt; is used for them (&lt;h3&gt; for subsections):
      &lt;h2&gt;&lt;a name="section1" /&gt;Section Headline&lt;h2&gt;
      &lt;h3&gt;Subsection Headline&lt;h3&gt;
     
    Headlines must never be used to increase the size of a text. Use &lt;b&gt; to make it stick out. The first letters of every word of a headline or link should be capitalized, apart from small words like "a", "to", etc.
     
    To allow better navigation through the site, each &lt;h2&gt; heading should be linked from a quicklinks section on top of the page:
      &lt;div id="quicklinks"&gt; [
        &lt;a href="section1"&gt;Section Headline&lt;/a&gt; |
        &lt;a href="section2"&gt;Second Section Headline&lt;/a&gt; |
        &lt;a href="section3"&gt;Third Section Headline&lt;/a&gt; ]
      &lt;div&gt;
     
    If you wish to link &lt;h3&gt; headlines as well, then you can use:
      &lt;div id="quicklinks"&gt;
      &lt;p&gt;
        &lt;b&gt;&lt;a href="section1"&gt;Section Headline&lt;/a&gt;&lt;/b&gt;: &lt;br /&gt; [
        &lt;a href="section11"&gt;Subsection Headline&lt;/a&gt; |
        &lt;a href="section21"&gt;Second Subsection Headline&lt;/a&gt; |  
        &lt;a href="section31"&gt;Third Subsection Headline&lt;/a&gt; ]
      &lt;p&gt;
      &lt;p&gt;
        &lt;b&gt;&lt;a href="section2"&gt;Second Section Headline&lt;/a&gt;&lt;/b&gt;: &lt;br /&gt; [
        &lt;a href="section21"&gt;Subsection Headline&lt;/a&gt; ]
      &lt;p&gt;
      &lt;div&gt;
     
    ==Own Header-Logo==
     
    Each site can have it's own right-side header-logo, like http://conference2006.kde.org. You just need to add a {{path|site.png}} to the toplevel directory of your site, the framework will add it automagically if it finds one. Look at http://conference2006.kde.org/site.png for the correct dimensions. While a transparent background would be prefered, atm the Internet Explorer has problems with transparent PNGs and GIFs are (were) problematic because of patents. Therefor the background needs atm to be duplicated in the image like done for the conference site.
     
    ==News==
     
    The <code>kde_general_news()</code> can be used to easily show a new story on a page.
     
      <?php
        kde_general_news($file, $items, $summaryonly)
      ?>
     
    The parameters of kde_general_news() are as follows:
    * <code>$file</code> - The relative path to the {{path|news.rdf}} file. This will generally be "{{path|./news.rdf}}".
    * <code>$items</code> - The number of news stories to show.
    * <code>$summaryonly</code> - Whether to show the summary only (e.g. for {{path|index.php}}) or the full stories ({{path|news.php}}).
     
    ==FAQs==
     
    A PHP class has been written to make it easy to write FAQs. It will always give a consistent formatting style. Using the class is simple:
     
      <?php
        $faq = new FAQ();
        $faq->addQuestion("This is the text of the question",
          "This is the text of the answer");
        $faq->show();
      ?> 
     
    Note: the page won't be rendered until you call <code>show()</code>.
    Please use this class rather than hand constructing a FAQ to save your time and to improve consistency.
     
    ==Image Galleries==
     
    A PHP class has been written to make it easy to write image galleries. The image galleries can link to enlarged versions of the image, but this isn't compulsory. Using the class is simple:
     
      <?php
        $gallery = new ImageGallery("Add a summary for screen readers here");
        $gallery->addImage("pics/image_sm.png", "pics/image.png", "640", "480",
          "Alt text", "Image caption (top)", "Image description (bottom)");
        $gallery->startNewRow();
        $gallery->addImage("pics/image_sm.png",  0, "640", "480",
          "Alt text", "Image caption (top)", "Image description (bottom)");
        $gallery->show();
      ?> 
     
    The first call to <code>addImage()</code> creates an image that can be clicked on to link to a larger version of the image. <code>startNewRow()</code> creates a new row. The second call to <code>addImage()</code> creates an image that isn't clickable (note the 0 rather than the URL to the large image).
     
    The parameters of <code>addImage()</code> are as follows:
      addImage($src_url, $dest_url, $width_pixels, $height_pixels,
              $alt_text, $caption_text, $description_text)
    * <code>$src_url</code> - The URL of the thumbnail image. If it is empty (""), then only caption and description will be shown.
    * <code>$dest_url</code> - The URL of the enlarged version of the image. The caption and the description will be links as well if <code>$dest_url</code> is specified.
    * <code>$width_pixels</code> - The width of the image in pixels
    * <code>$height_pixels</code> - The height of the image in pixels
    * <code>$alt_text</code> - A short description of the image for use in the alt="" tag (used by non-graphical browsers and screen readers)
    * <code>$caption_text</code> - A short caption which will appear above the image in bold (optional)
    * <code>$description_text</code> - A short description of the image which will appear underneath (optional)
     
    Note: the page won't be rendered until you call <code>show()</code>.
    Please use this class rather than hand constructing an image gallery to save your time and to improve consistency.
     
    ==Application Information Page==
     
    For web sites like koffice.org and edu.kde.org it makes sense to have a sub-directory for each program that is part of the project and in that sub-directory have a page which shows information about the program. The AppInfo class has been designed to make it easy to create such a page. It can be used as follows:
     
      <?php
        $appinfo = new AppInfo("KWord");
        $appinfo->setIcon( "pics/hi48-app-kword.png", "48", "48");
        $appinfo->setVersion($kwordversion);
        $appinfo->setLicense("lgpl");
        $appinfo->setCopyright("1998", "the KWord Team");
        $appinfo->addAuthor("Reginald Stadlbauer", "[email protected]");
        $appinfo->addAuthor("Torben Weis", "[email protected]");
        $appinfo->addContributor("David Faure", "[email protected]");
        $appinfo->addContributor("Thomas Zander", "[email protected]");
        $appinfo->addContributor("Shaheed Haque", "[email protected]");
        $appinfo->addContributor("Laurent Montel",
          "[email protected]");
        $appinfo->addContributor("Sven L&uuml;ppken", "[email protected]");
        $appinfo->show();
      ?>
     
    The second and third parameters of <code>setIcon()</code> are the width and height of the icon. The <code>addContributor()</code> function can take an optional third parameter, a short description of the person's function in the project.
     
    ==Common Mistakes==
     
    When converting pages, it is important to keep a few common mistakes in mind:
    Every page must have <code>$page_title</code> set to ensure correct rendering on all styles. This also means that the original heading must be removed. Otherwise the headline will be duplicated when setting <code>$page_title</code>.
     
    * All settings have to be made before {{path|header.inc}} is included.
    * There cannot be several links on the same page that use the same description for different URLs. This is required for compatibility with certain accessibility related solutions. &lt;a href="foo.php"&gt;More...&lt;/a&gt; should be replaced by &lt;a href="foo.php"&gt;More about KDE 3.x.y&lt;/a&gt;, etc.
    * The new layout uses UTF-8 as encoding. A lot of pages contain non-ASCII characters in names etc., make sure to either convert those to UTF-8 or use their HTML names.
    * The new layout uses XHTML. All tags without an end tag must be converted from &lt;tag&gt; to &lt;tag /&gt;, e.g. &lt;img src="..." alt="..." /&gt;. The alt attribute is required for a better accessibility of KDE.org. Additionally, attributes without a value are treated differently in XHTML, e.g. &lt;table nowrap&gt; would become &lt;table nowrap="nowrap"&gt;.
    * Please ensure that you use JPG or PNG images rather than GIF
    * Images for a particular {{path|area/directory}} should be placed under a {{path|pics/}} subdirectory
     
    ==404 Handler==
     
    All sites use a custom 404 handler page which is written in PHP. The handler is implemented in the <code>Handler404</code> class. It has these features:
    * If {{path|foo.html}} is requested and {{path|foo.php}} exists, the user is redirected to {{path|foo.php}}.
    * If {{path|foo.htm}} is requested and {{path|foo.php}} exists, the user is redirected to {{path|foo.php}}.
    * If {{path|foo.phtml}} is requested and {{path|foo.php}} exists, the user is redirected to {{path|foo.php}}.
    * etc...
     
    For pages which have changed location, a custom mapping can be added in {{path|www/media/404.php}} so that the user can be directed to just about anywhere.
     
      <?php
        include("handler.inc");
       
        $handler = new Handler404();
        $handler->add("/faq.html", "/faq");
        $handler->add("/events.html", "http://events.kde.org/");
        $handler->execute();
      ?>
     
    You must call <code>execute()</code> otherwise it won't work!

    Latest revision as of 17:48, 11 March 2016

    This page is now on the community wiki.