Source for file weblinks.php

Documentation is available at weblinks.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. /** ensure this file is being included by a parent file */
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. /** load the html drawing class */
  19. require_once$mainframe->getPath'front_html' ) );
  20. require_once$mainframe->getPath'class' ) );
  21. $mainframe->setPageTitleT_('Web Links') );
  22.  
  23. $task trimmosGetParam$_REQUEST'task'"" ) );
  24. $id intvalmosGetParam$_REQUEST'id') );
  25. $catid intvalmosGetParam$_REQUEST'catid') );
  26.  
  27. switch ($task{
  28.     case 'new':
  29.     editWebLink0$option );
  30.     break;
  31.  
  32.     case 'edit':
  33.     /** disabled until permissions system can handle it */
  34.     editWebLink0$option );
  35.     break;
  36.  
  37.     case 'save':
  38.     saveWebLink$option );
  39.     break;
  40.  
  41.     case 'cancel':
  42.     cancelWebLink$option );
  43.     break;
  44.  
  45.     case 'view':
  46.     showItem$id$catid );
  47.     break;
  48.  
  49.     default:
  50.     listWeblinks$catid );
  51.     break;
  52. }
  53.  
  54. function listWeblinks$catid {
  55.     global $mainframe$database$my;
  56.     global $mosConfig_shownoauth$mosConfig_live_site$mosConfig_absolute_path;
  57.     global $cur_template$Itemid;
  58.  
  59.     /* Query to retrieve all categories that belong under the web links section and that are published. */
  60.     $query "SELECT *, COUNT(a.id) AS numlinks FROM #__categories AS cc"
  61.     . "\n LEFT JOIN #__weblinks AS a ON a.catid = cc.id"
  62.     . "\n WHERE a.published='1' AND a.approved='1' AND section='com_weblinks' AND cc.published='1' AND cc.access <= '$my->gid'"
  63.     . "\n GROUP BY cc.id"
  64.     . "\n ORDER BY cc.ordering"
  65.     ;
  66.     $database->setQuery$query );
  67.     $categories $database->loadObjectList();
  68.  
  69.     $rows array();
  70.     $currentcat NULL;
  71.     if $catid {
  72.         // url links info for category
  73.         $query "SELECT id, url, title, description, date, hits, params FROM #__weblinks"
  74.         . "\nWHERE catid = '$catid' AND published='1' AND approved='1' AND archived=0"
  75.         . "\nORDER BY ordering"
  76.         ;
  77.         $database->setQuery$query );
  78.         $rows $database->loadObjectList();
  79.  
  80.         // current cate info
  81.         $query "SELECT name, description, image, image_position FROM #__categories"
  82.         . "\n WHERE id = '$catid'"
  83.         . "\n AND published = '1'"
  84.         ;
  85.         $database->setQuery$query );
  86.         $database->loadObject$currentcat );
  87.     }
  88.  
  89.     // Parameters
  90.     $menu =new mosMenu$database );
  91.     $menu->load$Itemid );
  92.     $params =new mosParameters$menu->params );
  93.     $params->def'page_title');
  94.     $params->def'header'$menu->name );
  95.     $params->def'pageclass_sfx''' );
  96.     $params->def'headings');
  97.     $params->def'hits'$mainframe->getCfg'hits' ) );
  98.     $params->def'item_description');
  99.     $params->def'other_cat_section');
  100.     $params->def'other_cat');
  101.     $params->def'description');
  102.     $params->def'description_text'T_('From the list below choose one of our web link categories, then select a URL to visit the site.') );
  103.     $params->def'image''-1' );
  104.     $params->def'weblink_icons''' );
  105.     $params->def'image_align''right' );
  106.     $params->def'back_button'$mainframe->getCfg'back_button' ) );
  107.  
  108.     if $catid {
  109.         $params->set'type''category' );
  110.     else {
  111.         $params->set'type''section' );
  112.     }
  113.     
  114.     // page description
  115.     $currentcat->descrip '';
  116.     if( ( @$currentcat->description <> '' {
  117.         $currentcat->descrip $currentcat->description;
  118.     else if !$catid {
  119.         // show description
  120.         if $params->get'description' ) ) {
  121.             $currentcat->descrip $params->get'description_text' );
  122.         }
  123.     }
  124.  
  125.     // page image
  126.     $currentcat->img '';
  127.     $path $mosConfig_live_site .'/images/stories/';
  128.     if ( ( @$currentcat->image <> '' {
  129.         $currentcat->img $path $currentcat->image;
  130.         $currentcat->align $currentcat->image_position;
  131.     else if !$catid {
  132.         if $params->get'image' <> -{
  133.             $currentcat->img $path $params->get'image' );
  134.             $currentcat->align $params->get'image_align' );
  135.         }
  136.     }
  137.  
  138.     // page header
  139.     $currentcat->header = '';
  140.     if @$currentcat->name <> '' {
  141.         $currentcat->header = $currentcat->name;
  142.         $pathway =mosPathway::getInstance();
  143.         $pathway->addItem($currentcat->name'');
  144.     else {
  145.         $currentcat->header = $params->get'header' );
  146.     }
  147.  
  148.     // used to show table rows in alternating colours
  149.     $tabclass array'sectiontableentry1''sectiontableentry2' );
  150.  
  151.     HTML_weblinks::displaylist$categories$rows$catid$currentcat$params$tabclass );
  152. }
  153.  
  154.  
  155. function showItem $id$catid {
  156.     global $database;
  157.  
  158.     //Record the hit
  159.     $sql="UPDATE #__weblinks SET hits = hits + 1 WHERE id = "$id ."";
  160.     $database->setQuery$sql );
  161.     $database->query();
  162.  
  163.     $database->setQuery"SELECT url FROM #__weblinks WHERE id = "$id ."" );
  164.     $url $database->loadResult();
  165.  
  166.     mosRedirect $url );
  167.  
  168.     listWeblinks$catid );
  169.  
  170. }
  171.  
  172. function editWebLink$id$option {
  173.     global $database$my;
  174.     global $mosConfig_absolute_path$mosConfig_live_site;
  175.  
  176.     if ($my->gid 1{
  177.         mosNotAuth();
  178.         return;
  179.     }
  180.  
  181.     $row new mosWeblink$database );
  182.     // load the row from the db table
  183.     $row->load$id );
  184.  
  185.     // fail if checked out not by 'me'
  186.     if ($row->checked_out && $row->checked_out <> $my->id{
  187.         mosRedirect"index2.php?option=$option",sprintf(T_('The module %s is currently being edited by another administrator.')$row->title) );
  188.     }
  189.  
  190.     if ($id{
  191.         $row->checkout$my->id );
  192.     else {
  193.         // initialise new record
  194.         $row->published         0;
  195.         $row->approved         0;
  196.         $row->ordering         0;
  197.     }
  198. /*
  199.     // make the select list for the image positions
  200.     $yesno[] = mosHTML::makeOption( '0', 'No' );
  201.     $yesno[] = mosHTML::makeOption( '1', 'Yes' );
  202.     // build the html select list
  203.     $applist = mosHTML::selectList( $yesno, 'approved', 'class="inputbox" size="2"', 'value', 'text', $row->approved );
  204.     // build the html select list for ordering
  205.     $query = "SELECT ordering AS value, title AS text"
  206.     . "\n FROM #__weblinks"
  207.     . "\n WHERE catid='$row->catid'"
  208.     . "\n ORDER BY ordering"
  209.     ;
  210.     $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 );
  211. */
  212.  
  213.     // build list of categories
  214.     require_once($mosConfig_absolute_path.'/administrator/includes/mosAdminMenus.php');
  215.     $lists['catid']             mosAdminMenus::ComponentCategory'catid'$optionintval$row->catid ) );
  216.  
  217.     HTML_weblinks::editWeblink$option$row$lists );
  218. }
  219.  
  220. function cancelWebLink$option {
  221.     global $database$my;
  222.  
  223.     if ($my->gid 1{
  224.         mosNotAuth();
  225.         return;
  226.     }
  227.  
  228.     $row new mosWeblink$database );
  229.     $row->id intvalmosGetParam$_POST'id') );
  230.     $row->checkin();
  231.     $Itemid mosGetParam$_POST'Returnid''' );
  232.     mosRedirect"index.php?Itemid=$Itemid);
  233. }
  234.  
  235. /**
  236. * Saves the record on an edit form submit
  237. @param database A database connector object
  238. */
  239. function saveWeblink$option {
  240.     global $database$my$mosConfig_absolute_path$mosConfig_mailfrom;
  241.  
  242.     if ($my->gid 1{
  243.         mosNotAuth();
  244.         return;
  245.     }
  246.  
  247.     $row new mosWeblink$database );
  248.     if (!$row->bind$_POST"approved published" )) {
  249.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  250.         exit();
  251.     }
  252.     // sanitize
  253.     $row->id intval($row->id);
  254.  
  255.     $isNew $row->id 1;
  256.  
  257.     $row->date = date"Y-m-d H:i:s" );
  258.  
  259.         $row->title $database->getEscaped($row->title);
  260.         $row->catid $database->getEscaped($row->catid);
  261.  
  262.     if (!$row->check()) {
  263.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  264.         exit();
  265.     }
  266.     if (!$row->store()) {
  267.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  268.         exit();
  269.     }
  270.     $row->checkin();
  271.  
  272.     // messaging for new items
  273.     require_once$mosConfig_absolute_path .'/components/com_messages/messages.class.php' );
  274.  
  275.     $query "SELECT id,email FROM #__users WHERE sendEmail = '1'";            
  276.     $database->setQuery$query );
  277.     $rows $database->loadObjectList();
  278.  
  279.     foreach ($rows as $user{    
  280.     
  281.         // admin message
  282.         $msg new mosMessage$database );
  283.         $msg->send$my->id$user->idT_("New Item")sprintfT_('A new WebLink has been submitted by [ %s ]  titled [ %s ] ')$my->username$row->title ) );
  284.         
  285.         // email message
  286.         mosMail $mosConfig_mailfrom$mosConfig_mailfrom$user->email"A new Web Link has been submitted"'A new WebLink has been submitted by ['.$my->username.'] titled ['.$row->title.']. Please login to view and approve it.');
  287.     
  288.     }
  289.  
  290.     $msg     $isNew T_('Thanks for your submission; it will be reviewed before being posted to the site.''';
  291.     $Itemid mosGetParam$_POST'Returnid''' );
  292.     mosRedirect'index.php?Itemid='$Itemid$msg );
  293. }
  294.  
  295. ?>

Documentation generated on Mon, 05 May 2008 16:24:16 +0400 by phpDocumentor 1.4.0