Source for file content.php

Documentation is available at content.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Content
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. require_once$mainframe->getPath'front_html''com_content' ) );
  14. require_once($mainframe->getPath('class'));
  15.  
  16. $id            intvalmosGetParam$_REQUEST'id') );
  17. $sectionid     intvalmosGetParam$_REQUEST'sectionid') );
  18. $pop         intvalmosGetParam$_REQUEST'pop') );
  19. $task         trimmosGetParam$_REQUEST'task''' ) );
  20. $limit         intvalmosGetParam$_REQUEST'limit''' ) );
  21. $limitstart intvalmosGetParam$_REQUEST'limitstart') );
  22.  
  23. $now date'Y-m-d H:i:s'time($mosConfig_offset 60 60 );
  24.  
  25. // Editor usertype check
  26. $access new stdClass();
  27. $access->canEdit     $acl->acl_check'action''edit''users'$my->usertype'content''all' );
  28. $access->canEditOwn $acl->acl_check'action''edit''users'$my->usertype'content''own' );
  29. $access->canPublish $acl->acl_check'action''publish''users'$my->usertype'content''all' );
  30.  
  31. // cache activation
  32. $cache =mosCache::getCache'com_content' );
  33.  
  34. // loads function for frontpage component
  35. if $option == 'com_frontpage' {
  36.     //frontpage( $option, $gid, $pop, $now );
  37.     $cache->call'frontpage'$gid$access$pop$now );
  38.     return;
  39. }
  40.  
  41. switch strtolower$task ) ) {
  42.     case 'findkey':
  43.         findKeyItem$gid$access$pop$option$now );
  44.         break;
  45.  
  46.     case 'view':
  47.         showItem$id$gid$access$pop$option$now );
  48.         break;
  49.  
  50.     case 'section':
  51.         $cache->call'showSection'$id$gid$access$now );
  52.         break;
  53.  
  54.     case 'category':
  55.         $cache->call'showCategory'$id$gid$access$sectionid$limit$limitstart$now );
  56.         break;
  57.  
  58.     case 'blogsection':
  59.         $cache->call('showBlogSection'$id$gid$access$pop$now );
  60.         break;
  61.  
  62.     case 'blogcategorymulti':
  63.     case 'blogcategory':
  64.         $cache->call'showBlogCategory'$id$gid$access$pop$now );
  65.         break;
  66.  
  67.     case 'archivesection':
  68.         showArchiveSection$id$gid$access$pop$option );
  69.         break;
  70.  
  71.     case 'archivecategory':
  72.         showArchiveCategory$id$gid$access$pop$option$now );
  73.         break;
  74.  
  75.     case 'edit':
  76.         editItem$id$gid$access0$task$Itemid );
  77.         break;
  78.  
  79.     case 'new':
  80.         editItem0$gid$access$sectionid$task$Itemid );
  81.         break;
  82.  
  83.     case 'save':
  84.         mosCache::cleanCache'com_content' );
  85.         saveContent$access );
  86.         break;
  87.  
  88.     case 'cancel':
  89.         cancelContent$access );
  90.         break;
  91.  
  92.     case 'emailform':
  93.         emailContentForm$id );
  94.         break;
  95.  
  96.     case 'emailsend':
  97.         emailContentSend$id );
  98.         break;
  99.  
  100.     case 'vote':
  101.         recordVote $url $user_rating $cid $database);
  102.         break;
  103.  
  104.     default:
  105.         $cache->call('showBlogSection'0$gid$access$pop$now );
  106.         break;
  107. }
  108.  
  109. /**
  110.  * Searches for an item by a key parameter
  111.  * @param int The user access level
  112.  * @param object Actions this user can perform
  113.  * @param int 
  114.  * @param string The url option
  115.  * @param string A timestamp
  116.  */
  117. function findKeyItem$gid$access$pop$option$now {
  118.     global $database;
  119.     $keyref mosGetParam$_REQUEST'keyref''' );
  120.     $keyref $database->getEscaped$keyref );
  121.  
  122.     $query 'SELECT id
  123.         FROM #__content
  124.         WHERE attribs LIKE \'%keyref=' $keyref '%\'
  125.         ';
  126.     $database->setQuery$query );
  127.     $id $database->loadResult();
  128.     if ($id 0{
  129.         showItem$id$gid$access$pop$option$now );
  130.     else {
  131.         echo 'Key not found '$keyref;
  132.     }
  133. }
  134.  
  135. function frontpage$gid&$access$pop$now {
  136.     global $database$mainframe$my$Itemid;
  137.     global $mosConfig_offset;
  138.  
  139.     $noauth !$mainframe->getCfg'shownoauth' );
  140.  
  141.     // Parameters
  142.     $menu =new mosMenu$database );
  143.     $menu->load$Itemid );
  144.     $params =new mosParameters$menu->params );
  145.     $orderby_sec $params->def'orderby_sec''' );
  146.     $orderby_pri $params->def'orderby_pri''' );
  147.     $header $params->def'header'$menu->name );
  148.     $page_title $params->def'page_title');
  149.     // Ordering control
  150.     $order_sec _orderby_sec$orderby_sec );
  151.     $order_pri _orderby_pri$orderby_pri );
  152.  
  153.     $now date"Y-m-d H:i:s"time()+$mosConfig_offset*60*60 );
  154.  
  155.     global $acl;
  156.     $viewAccess ($gid >= $acl->get_group_id'Registered''ARO' 0($gid >= $acl->get_group_id'Author''ARO' 0);
  157.     // query records
  158.     $query "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, cc.name AS category, g.name AS groups"
  159.     . "\n FROM #__content AS a"
  160.     . "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
  161.     . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
  162.     . "\n LEFT JOIN #__sections AS s ON s.id = a.sectionid"
  163.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  164.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  165.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  166.     . "\n WHERE a.state = '1'"
  167.     . $noauth "\n AND a.access <= '"$my->gid ."'" '' )
  168.     . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )"
  169.     . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
  170.     . "\n AND a.access <= "$viewAccess
  171.     . "\n ORDER BY "$order_pri $order_sec
  172.     ;
  173.     $rows $database->doSQLget($query'mosExtendedContent');
  174.  
  175.     // Dynamic Page Title
  176.     $mainframe->SetPageTitle$header );
  177.  
  178.     BlogOutput$rows$params$gid$access$pop$menu );
  179. }
  180.  
  181.  
  182. function showSection$id$gid&$access$now {
  183.     global $database$mainframe$mosConfig_offset$Itemid;
  184.  
  185.     $noauth !$mainframe->getCfg'shownoauth' );
  186.  
  187.     // Paramters
  188.     $params new stdClass();
  189.     if $Itemid {
  190.         $menu new mosMenu$database );
  191.         $menu->load$Itemid );
  192.         $params =new mosParameters$menu->params );
  193.     else {
  194.         $menu "";
  195.         $params =new mosEmpty();
  196.  
  197.     }
  198.     $orderby $params->get'orderby''' );
  199.  
  200.     $params->set'type''section' );
  201.  
  202.     $params->def'page_title');
  203.     $params->def'pageclass_sfx''' );
  204.     $params->def'other_cat_section');
  205.     $params->def'other_cat');
  206.     $params->def'empty_cat');
  207.     $params->def'cat_items');
  208.     $params->def'cat_description');
  209.     $params->def'description');
  210.     $params->def'description-image');
  211.     $params->def'back_button'$mainframe->getCfg'back_button' ) );
  212.     $params->def'pageclass_sfx''' );
  213.  
  214.     // Ordering control
  215.     $orderby _orderby_sec$orderby );
  216.  
  217.     $section new mosSection$database );
  218.     $section->load$id );
  219.  
  220.     if $access->canEdit {
  221.         $xwhere '';
  222.         $xwhere2 "\n AND b.state >= '0'";
  223.     else {
  224.         $xwhere "\n AND a.published = '1'";
  225.         $xwhere2 "\n AND b.state = '1'"
  226.         . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '"$now ."' )"
  227.         . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '"$now ."' )"
  228.         ;
  229.     }
  230.  
  231.     // show/hide empty categories
  232.     if $params->get'empty_cat' ) ) {
  233.         $empty '';
  234.     else {
  235.         $empty "\n HAVING COUNT( b.id ) > 0";
  236.     }
  237.  
  238.     // Main Query
  239.     $query '
  240.         SELECT a.*, COUNT( b.id ) AS numitems
  241.         FROM #__categories AS a
  242.         LEFT JOIN #__content AS b ON b.catid = a.id '$xwhere2 .'
  243.         WHERE a.section = \'' $section->id .'\' '$xwhere;
  244.     if ($noauth{
  245.         $query .= '
  246.         AND a.access <= '$gid;
  247.     }
  248.     $query .= '
  249.         GROUP BY a.id
  250.         ' $empty '
  251.         ORDER BY ' $orderby;
  252.  
  253.     $database->setQuery$query );
  254.     $other_categories $database->loadObjectList();
  255.  
  256.     // Dynamic Page Title
  257.     $mainframe->SetPageTitle$menu->name );
  258.  
  259.     HTML_content::showContentList$sectionNULL$access$idNULL,  $gid$paramsNULL$other_categoriesNULL );
  260. }
  261.  
  262.  
  263. /**
  264. @param int The category id
  265. @param int The group id of the user
  266. @param int The access level of the user
  267. @param int The section id
  268. @param int The number of items to dislpay
  269. @param int The offset for pagination
  270. */
  271. function showCategory$id$gid&$access$sectionid$limit$limitstart$now  {
  272.     global $database$mainframe$Itemid$mosConfig_offset$mosConfig_list_limit;
  273.  
  274.     $noauth !$mainframe->getCfg'shownoauth' );
  275.     $selected mosGetParam$_POST'order''' );
  276.  
  277.     // Paramters
  278.     $params new stdClass();
  279.     if $Itemid {
  280.         $menu new mosMenu$database );
  281.         $menu->load$Itemid );
  282.         $params =new mosParameters$menu->params );
  283.     else {
  284.         $menu "";
  285.         $params =new mosParameters'' );
  286.     }
  287.  
  288.     if $selected {
  289.         $orderby $selected;
  290.     else {
  291.         $orderby $params->get'orderby''rdate' );
  292.         $selected $orderby;
  293.     }
  294.  
  295.     $params->set'type''category' );
  296.  
  297.     $params->def'page_title');
  298.     $params->def'title');
  299.     $params->def'hits'$mainframe->getCfg'hits' ) );
  300.     $params->def'author'!$mainframe->getCfg'hideAuthor' ) );
  301.     $params->def'date'!$mainframe->getCfg'hideCreateDate' ) );
  302.     $params->def'date_format'_DATE_FORMAT_LC );
  303.     $params->def'navigation');
  304.     $params->def'display');
  305.     $params->def'display_num'$mosConfig_list_limit );
  306.     $params->def'other_cat');
  307.     $params->def'empty_cat');
  308.     $params->def'cat_items');
  309.     $params->def'cat_description');
  310.     $params->def'description');
  311.     $params->def'description-image');
  312.     $params->def'back_button'$mainframe->getCfg'back_button' ) );
  313.     $params->def'pageclass_sfx''' );
  314.     $params->def'headings');
  315.     $params->def'order_select');
  316.     $params->def'filter');
  317.     $params->def'filter_type''title' );
  318.  
  319.     // Ordering control
  320.     $orderby _orderby_sec$orderby );
  321.  
  322.     $category new mosCategory$database );
  323.     $category->load$id );
  324.  
  325.     if $sectionid == {
  326.         $sectionid $category->section;
  327.     }
  328.  
  329.     $pathway =mosPathway::getInstance();
  330.     $pathway->addItem($category->titlecategoryURL($sectionid$id));
  331.  
  332.     if $access->canEdit {
  333.         $xwhere '';
  334.         $xwhere2 "\n AND b.state >= '0'";
  335.     else {
  336.         $xwhere "\n AND c.published='1'";
  337.         $xwhere2 "\n AND b.state='1'"
  338.         . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '"$now ."' )"
  339.         . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '"$now ."' )"
  340.         ;
  341.     }
  342.  
  343.     $pagetitle '';
  344.     if $Itemid {
  345.         $menu new mosMenu$database );
  346.         $menu->load$Itemid );
  347.         $pagetitle $menu->name;
  348.     // if
  349.  
  350.     // show/hide empty categories
  351.     $empty '';
  352.     if !$params->get'empty_cat' ) )
  353.         $empty "\n HAVING COUNT( b.id ) > 0";
  354.  
  355.     // get the list of other categories
  356.     $query "SELECT c.*, COUNT( b.id ) AS numitems"
  357.     . "\n FROM #__categories AS c"
  358.     . "\n LEFT JOIN #__content AS b ON b.catid = c.id "
  359.     . $xwhere2
  360.     . $noauth "\n AND b.access <= '"$gid ."'" '' )
  361.     . "\n WHERE c.section = '"$category->section"'"
  362.     . $xwhere
  363.     . $noauth "\n AND c.access <= '"$gid ."'" '' )
  364.     . "\n GROUP BY c.id"
  365.     . $empty
  366.     . "\n ORDER BY c.ordering"
  367.     ;
  368.     $database->setQuery$query );
  369.     $other_categories $database->loadObjectList();
  370.  
  371.     // get the total number of published items in the category
  372.     // filter functionality
  373.     $_and '';
  374.     if ($filter mosGetParam($_POST'filter''')) {
  375.         $filter strtolower$filter );
  376.         $filter $database->getEscaped($filter);
  377.         if $params->get'filter' ) ) {
  378.             switch $params->get'filter_type' ) ) {
  379.                 case 'title':
  380.                     $_and "\n AND LOWER( a.title ) LIKE '%"$filter ."%'";
  381.                     break;
  382.                 case 'author':
  383.                     $_and "\n AND ( ( LOWER( u.name ) LIKE '%"$filter ."%' ) OR ( LOWER( a.created_by_alias ) LIKE '%"$filter ."%' ) )";
  384.                     break;
  385.                 case 'hits':
  386.                     $_and "\n AND a.hits LIKE '%"$filter ."%'";
  387.                     break;
  388.             }
  389.         }
  390.  
  391.     }
  392.  
  393.     if $access->canEdit {
  394.         $xwhere "\n AND a.state >= '0'";
  395.     else {
  396.         $xwhere "\n AND a.state='1'"
  397.         . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
  398.         . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
  399.         ;
  400.     }
  401.  
  402.     $query "SELECT COUNT(a.id) as numitems"
  403.     . "\n FROM #__content AS a"
  404.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  405.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  406.     . "\n WHERE a.catid='"$category->id ."' "$xwhere
  407.     . $noauth "\n AND a.access<='"$gid ."'" '' )
  408.     . "\n AND '"$category->access ."'<='"$gid ."'"
  409.     . $_and
  410.     . "\n ORDER BY "$orderby .""
  411.     ;
  412.     $database->setQuery$query );
  413.     $counter $database->loadObjectList();
  414.     $total $counter[0]->numitems;
  415.     $limit $limit $limit $params->get'display_num' ;
  416.     if $total <= $limit $limitstart 0;
  417.  
  418.     require_once$GLOBALS['mosConfig_absolute_path''/includes/pageNavigation.php' );
  419.     $pageNav new mosPageNav$total$limitstart$limit );
  420.  
  421.     // get the list of items for this category
  422.     $query "SELECT a.id, a.title, a.hits, a.created_by, a.created_by_alias, a.created AS created, a.access, u.name AS author, a.state, g.name AS groups"
  423.     . "\n FROM #__content AS a"
  424.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  425.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  426.     . "\n WHERE a.catid='"$category->id ."' "$xwhere
  427.     . $noauth "\n AND a.access<='"$gid ."'" '' )
  428.     . "\n AND '"$category->access ."'<='"$gid ."'"
  429.     . $_and
  430.     . "\n ORDER BY "$orderby .""
  431.     . "\n LIMIT "$limitstart .", "$limit
  432.     ;
  433.     $database->setQuery$query );
  434.     $items $database->loadObjectList();
  435.  
  436.     $check 0;
  437.     if $params->get'date' ) ) {
  438.         $order[mosHTML::makeOption'date'T_('Date Asc') );
  439.         $order[mosHTML::makeOption'rdate'T_('Date Desc'));
  440.         $check .= 1;
  441.     }
  442.     if $params->get'title' ) ) {
  443.         $order[mosHTML::makeOption'alpha'T_('Title Asc') );
  444.         $order[mosHTML::makeOption'ralpha'T_('Title Desc') );
  445.         $check .= 1;
  446.     }
  447.     if $params->get'hits' ) ) {
  448.         $order[mosHTML::makeOption'hits'T_('Hits Asc') );
  449.         $order[mosHTML::makeOption'rhits'T_('Hits Desc') );
  450.         $check .= 1;
  451.     }
  452.     if $params->get'author' ) ) {
  453.         $order[mosHTML::makeOption'author'T_('Author Asc') );
  454.         $order[mosHTML::makeOption'rauthor'T_('Author Desc') );
  455.         $check .= 1;
  456.     }
  457.     $order[mosHTML::makeOption'order'T_('Ordering') );
  458.     $lists['order'mosHTML::selectList$order'order''class="inputbox" size="1"  onchange="document.adminForm.submit();"''value''text'$selected );
  459.     if $check {
  460.         $lists['order''';
  461.         $params->set'order_select');
  462.     }
  463.  
  464.     $lists['task''category';
  465.     $lists['filter'$filter;
  466.  
  467.     // Dynamic Page Title
  468.     $mainframe->SetPageTitle$pagetitle );
  469.  
  470.     HTML_content::showContentList$category$items$access$id$sectionid$gid$params$pageNav$other_categories$lists );
  471. // showCategory
  472.  
  473.  
  474. function showBlogSection$id=0$gid&$access$pop$now=NULL {
  475.     global $database$mainframe$mosConfig_offset$Itemid;
  476.  
  477.     $noauth !$mainframe->getCfg'shownoauth' );
  478.  
  479.     // Parameters
  480.     $params new stdClass();
  481.     if $Itemid {
  482.         $menu new mosMenu$database );
  483.         $menu->load$Itemid );
  484.         $params =new mosParameters$menu->params );
  485.     else {
  486.         $menu "";
  487.         $params =new mosParameters'' );
  488.     }
  489.  
  490.     // new blog multiple section handling
  491.     if !$id {
  492.         $id        $params->def'sectionid');
  493.     }
  494.  
  495.     $where         _where1$access$noauth$gid$id$now );
  496.  
  497.     // Ordering control
  498.     $orderby_sec     $params->def'orderby_sec''rdate' );
  499.     $orderby_pri     $params->def'orderby_pri''' );
  500.     $order_sec     _orderby_sec$orderby_sec );
  501.     $order_pri     _orderby_pri$orderby_pri );
  502.  
  503.     // Main data query
  504.     $query "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, g.name AS groups"
  505.     . "\n FROM #__content AS a"
  506.     . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
  507.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  508.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  509.     . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id"
  510.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  511.     . count$where "\n WHERE ".implode"\n AND "$where '' )
  512.     . "\n AND s.access<=$gid"
  513.     . "\n ORDER BY "$order_pri $order_sec
  514.     ;
  515. //    $database->setQuery( $query );
  516. //    $rows = $database->loadObjectList();
  517.     $rows $database->doSQLget($query'mosExtendedContent');
  518.  
  519.     // Dynamic Page Title
  520.     if ($menu{
  521.         $mainframe->setPageTitle$menu->name );
  522.     }
  523.  
  524.     BlogOutput$rows$params$gid$access$pop$menu );
  525. }
  526.  
  527. function showBlogCategory$id=0$gid&$access$pop$now {
  528.     global $database$mainframe$mosConfig_offset$Itemid;
  529.  
  530.     $noauth !$mainframe->getCfg'shownoauth' );
  531.  
  532.     // Paramters
  533.     $params new stdClass();
  534.     if $Itemid {
  535.         $menu new mosMenu$database );
  536.         $menu->load$Itemid );
  537.         $params =new mosParameters$menu->params );
  538.     else {
  539.         $menu "";
  540.         $params =new mosParameters'' );
  541.     }
  542.  
  543.     // new blog multiple section handling
  544.     if !$id {
  545.         $id         $params->def'categoryid');
  546.     }
  547.  
  548.     $where        _where2$access$noauth$gid$id$now );
  549.  
  550.     // Ordering control
  551.     $orderby_sec     $params->def'orderby_sec''rdate' );
  552.     $orderby_pri     $params->def'orderby_pri''' );
  553.     $order_sec     _orderby_sec$orderby_sec );
  554.     $order_pri     _orderby_pri$orderby_pri );
  555.  
  556.     // Main data query
  557.     $query "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, g.name AS groups, cc.name AS category"
  558.     . "\n FROM #__content AS a"
  559.     . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
  560.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  561.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  562.     . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id"
  563.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  564.     . count$where "\n WHERE ".implode"\n AND "$where '' )
  565.     . "\n AND s.access <= "$gid
  566.     . "\n ORDER BY "$order_pri $order_sec;
  567.     ;
  568. //    $database->setQuery( $query );
  569. //    $rows = $database->loadObjectList();
  570.     $rows $database->doSQLget($query'mosExtendedContent');
  571.  
  572.     // Dynamic Page Title
  573.     $mainframe->SetPageTitle$menu->name );
  574.  
  575.     BlogOutput$rows$params$gid$access$pop$menu );
  576. }
  577.  
  578. function showArchiveSection$id=NULL$gid&$access$pop$option {
  579.     global $database$mainframe$mosConfig_offset;
  580.     global $Itemid;
  581.  
  582.     $noauth !$mainframe->getCfg'shownoauth' );
  583.  
  584.     // Parameters
  585.     $year     mosGetParam$_REQUEST'year'MosFormatDatedate("Y-m-d H:i:s")'QY' ) );
  586.     $month     mosGetParam$_REQUEST'month'MosFormatDatedate("Y-m-d H:i:s")'Qm' ) );
  587.  
  588.     $params new stdClass();
  589.     if $Itemid {
  590.         $menu new mosMenu$database );
  591.         $menu->load$Itemid );
  592.         $params =new mosParameters$menu->params );
  593.     else {
  594.         $menu "";
  595.         $params =new mosParameters'' );
  596.     }
  597.  
  598.     $params->set'intro_only');
  599.     $params->set'year'$year );
  600.     $params->set'month'$month );
  601.  
  602.     // Ordering control
  603.     $orderby_sec $params->def'orderby_sec''rdate' );
  604.     $orderby_pri $params->def'orderby_pri''' );
  605.     $order_sec _orderby_sec$orderby_sec );
  606.     $order_pri _orderby_pri$orderby_pri );
  607.  
  608.     // used in query
  609.     $where _where-1$access$noauth$gid$idNULL$year$month );
  610.  
  611.     // checks to see if 'All Sections' options used
  612.     if $id == {
  613.         $check '';
  614.     else {
  615.         $check 'AND a.sectionid = '$id ;
  616.     }
  617.     // query to determine if there are any archived entries for the section
  618.     $query =     "SELECT a.id"
  619.     . "\n FROM #__content as a"
  620.     . "\n WHERE a.state = '-1'"
  621.     . $check
  622.     ;
  623.     $database->setQuery$query );
  624.     $items $database->loadObjectList();
  625.     $archives count$items );
  626.  
  627.     // Main Query
  628.     $query "SELECT a.*, ROUND(v.rating_sum/v.rating_count) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, g.name AS groups"
  629.     . "\n FROM #__content AS a"
  630.     . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
  631.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  632.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  633.     . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id"
  634.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  635.     . count$where "\n WHERE "implode"\n AND "$where '')
  636.     . "\n AND s.access <= "$gid
  637.     . "\n ORDER BY "$order_pri $order_sec
  638.     ;
  639. //    $database->setQuery( $query );
  640. //    $rows = $database->loadObjectList();
  641.     $rows $database->doSQLget($query'mosExtendedContent');
  642.  
  643.     // initiate form
  644.      echo '<form action="'.sefRelToAbs'index.php').'" method="post">';
  645.  
  646.     // Dynamic Page Title
  647.     $mainframe->SetPageTitle$menu->name );
  648.  
  649.     if !$archives {
  650.         // if no archives for category, hides search and outputs empty message
  651.         echo '<br /><div align="center">'T_('There are currently no Archived Entries for this Category'.'</div>';
  652.     else {
  653.         BlogOutput$rows$params$gid$access$pop$menu);
  654.     }
  655.  
  656.      echo '<input type="hidden" name="id" value="'$id .'" />';
  657.     echo '<input type="hidden" name="Itemid" value="'$Itemid .'" />';
  658.      echo '<input type="hidden" name="task" value="archivesection" />';
  659.      echo '<input type="hidden" name="option" value="com_content" />';
  660.      echo '<input type="hidden" name="module" value="1" />';
  661.      echo '</form>';
  662. }
  663.  
  664.  
  665. function showArchiveCategory$id=0$gid&$access$pop$option$now {
  666.     global $database$mainframe$mosConfig_offset;
  667.     global $Itemid;
  668.  
  669.     // Parameters
  670.     $noauth !$mainframe->getCfg'shownoauth' );
  671.     $year     mosGetParam$_REQUEST'year'MosFormatDatedate("Y-m-d H:i:s")'QY' ) );
  672.     $month     mosGetParam$_REQUEST'month'MosFormatDatedate("Y-m-d H:i:s")'Qm' ) );
  673.     $module trimmosGetParam$_REQUEST'module''' ) );
  674.  
  675.     // used by archive module
  676.     if $module {
  677.         $check '';
  678.     else {
  679.         $check 'AND a.catid = '$id;
  680.     }
  681.  
  682.     if $Itemid {
  683.         $menu new mosMenu$database );
  684.         $menu->load$Itemid );
  685.         $params =new mosParameters$menu->params );
  686.     else {
  687.         $menu "";
  688.         $params =new mosParameters'' );
  689.     }
  690.  
  691.     $params->set'year'$year );
  692.     $params->set'month'$month );
  693.  
  694.     // Ordering control
  695.     $orderby_sec $params->def'orderby''rdate' );
  696.     $order_sec _orderby_sec$orderby_sec );
  697.  
  698.     // used in query
  699.     $where _where-2$access$noauth$gid$idNULL$year$month );
  700.  
  701.     // query to determine if there are any archived entries for the category
  702.     $query =     "SELECT a.id"
  703.     . "\n FROM #__content as a"
  704.     . "\n WHERE a.state = '-1'"
  705.     . "\n "$check
  706.     ;
  707.     $database->setQuery$query );
  708.     $items $database->loadObjectList();
  709.     $archives count$items );
  710.  
  711.     $query "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, g.name AS groups"
  712.     . "\n FROM #__content AS a"
  713.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  714.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  715.     . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id"
  716.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  717.     . count$where "\n WHERE "implode"\n AND "$where '' )
  718.     . "\n AND s.access <= "$gid
  719.     . "\n ORDER BY "$order_sec
  720.     ;
  721. //    $database->setQuery( $query );
  722. //    $rows = $database->loadObjectList();
  723.     $rows $database->doSQLget($query'mosExtendedContent');
  724.  
  725.     // initiate form
  726.      echo '<form action="'.sefRelToAbs'index.php').'" method="post">';
  727.  
  728.     // Page Title
  729.     $mainframe->SetPageTitle$menu->name );
  730.  
  731.     if !$archives {
  732.         // if no archives for category, hides search and outputs empty message
  733.         echo '<br /><div align="center">'T_('There are currently no Archived Entries for this Category'.'</div>';
  734.     else {
  735.         BlogOutput$rows$params$gid$access$pop$menu);
  736.     }
  737.  
  738.      echo '<input type="hidden" name="id" value="'$id .'" />';
  739.     echo '<input type="hidden" name="Itemid" value="'$Itemid .'" />';
  740.      echo '<input type="hidden" name="task" value="archivecategory" />';
  741.      echo '<input type="hidden" name="option" value="com_content" />';
  742.      echo '<input type="hidden" name="module" value="1" />';
  743.      echo '</form>';
  744. }
  745.  
  746.  
  747. function BlogOutput &$rows&$params$gid&$access$pop&$menu$archive=NULL {
  748.     global $mainframe$Itemid$task$id$option$database$mosConfig_live_site;
  749.  
  750.     // parameters
  751.     if $params->get'page_title'&& $menu{
  752.         $header $params->def'header'$menu->name );
  753.     else {
  754.         $header '';
  755.     }
  756.     $columns $params->def'columns');
  757.     if $columns == {
  758.         $columns 1;
  759.     }
  760.     $intro                 $params->def'intro');
  761.     $leading                 $params->def'leading');
  762.     $links                 $params->def'link');
  763.     $pagination             $params->def'pagination');
  764.     $pagination_results     $params->def'pagination_results');
  765.     $pagination_results     $params->def'pagination_results');
  766.     $descrip                 $params->def'description');
  767.     $descrip_image             $params->def'description_image');
  768.     // needed for back button for page
  769.     $back                 $params->get'back_button'$mainframe->getCfg'back_button' ) );
  770.     // needed to disable back button for item
  771.     $params->set'back_button');
  772.     $params->def'pageclass_sfx''' );
  773.     $params->set'intro_only');
  774.  
  775.     $total count$rows );
  776.  
  777.     // pagination support
  778.     $limitstart intvalmosGetParam$_REQUEST'limitstart') );
  779.     $limit $intro $leading $links;
  780.     if $total <= $limit {
  781.         $limitstart 0;
  782.     }
  783.     $i $limitstart;
  784.  
  785.     // needed to reduce queries used by getItemid
  786.     require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php');
  787.     $handler =new contentHandler();
  788.     $ItemidCount['bs']         $handler->getBlogSectionCount();
  789.     $ItemidCount['bc']         $handler->getBlogCategoryCount();
  790.     $ItemidCount['gbs']     $handler->getGlobalBlogSectionCount();
  791.  
  792.     // used to display section/catagory description text and images
  793.     // currently not supported in Archives
  794.     if $menu && $menu->componentid && $descrip || $descrip_image ) ) {
  795.         switch $menu->type {
  796.             case 'content_blog_section':
  797.                 $description new mosSection$database );
  798.                 $description->load$menu->componentid );
  799.                 break;
  800.  
  801.             case 'content_blog_category':
  802.                 $description new mosCategory$database );
  803.                 $description->load$menu->componentid );
  804.                 break;
  805.  
  806.             default:
  807.                 $menu->componentid 0;
  808.                 break;
  809.         }
  810.     }
  811.  
  812.     // Page Output
  813.     // page header
  814.     if $header {
  815.         echo '<div class="componentheading'$params->get'pageclass_sfx' .'">'$header .'</div>';
  816.     }
  817.  
  818.     if $archive {
  819.         echo '<br />';
  820.         echo mosHTML::monthSelectList'month''size="1" class="inputbox"'$params->get'month' ) );
  821.         echo mosHTML::integerSelectList138013901'year''size="1" class="inputbox"'$params->get'year' )"%04d" );
  822.         echo '<input type="submit" class="button" value="دریافت نتیجه"/>';
  823.     }
  824.  
  825.     // checks to see if there are there any items to display
  826.     if $total {
  827.         $col_with 100 $columns;            // width of each column
  828.         $width 'width="'$col_with .'%"';
  829.  
  830.         if $archive {
  831.             // Search Success message
  832.             $msg sprintfT_('Here are the Archived entries for %s %s')Convertnumber2farsi($params->get'month' ))Convertnumber2farsi($params->get'year' )) );
  833.             echo "<br /><br /><div align='center'>"$msg ."</div><br /><br />";
  834.         }
  835.         echo '<table class="blog' $params->get'pageclass_sfx' '" cellpadding="0" cellspacing="0">';
  836.  
  837.         // Secrion/Category Description & Image
  838.         if $menu && $menu->componentid && $descrip || $descrip_image ) ) {
  839.             $link $mosConfig_live_site .'/images/stories/'$description->image;
  840.             echo '<tr>';
  841.             echo '<td valign="top">';
  842.             if $descrip_image && $description->image {
  843.                 echo '<img src="'$link .'" align="'$description->image_position .'" hspace="6" alt="" />';
  844.             }
  845.             if $descrip && $description->description {
  846.                 echo $description->description;
  847.             }
  848.             echo '<br/><br/>';
  849.             echo '</td>';
  850.             echo '</tr>';
  851.         }
  852.  
  853.         // Leading story output
  854.         if $leading {
  855.             echo '<tr>';
  856.             echo '<td valign="top">';
  857.             for $z 0$z $leading$z++ {
  858.                 if $i >= $total {
  859.                     // stops loop if total number of items is less than the number set to display as leading
  860.                     break;
  861.                 }
  862.                 echo '<div>';
  863.                 show$rows[$i]$params$gid$access$pop$option$ItemidCount );
  864.                 echo '</div>';
  865.                 $i++;
  866.             }
  867.             echo '</td>';
  868.             echo '</tr>';
  869.         }
  870.  
  871.         if $intro && $i $total ) ) {
  872.             echo '<tr>';
  873.             echo '<td valign="top">';
  874.             echo '<table width="100%"  cellpadding="0" cellspacing="0">';
  875.             // intro story output
  876.             for $z 0$z $intro$z++ {
  877.                 if $i >= $total {
  878.                     // stops loop if total number of items is less than the number set to display as intro + leading
  879.                     break;
  880.                 }
  881.  
  882.                 if !$z $columns || $columns == {
  883.                     echo '<tr>';
  884.                 }
  885.  
  886.                 echo '<td valign="top" '$width .'>';
  887.  
  888.                 // outputs either intro or only a link
  889.                 if $z $intro {
  890.                     show$rows[$i]$params$gid$access$pop$option$ItemidCount );
  891.                 else {
  892.                     echo '</td>';
  893.                     echo '</tr>';
  894.                     break;
  895.                 }
  896.  
  897.                 echo '</td>';
  898.  
  899.                 if !( ( $z $columns || $columns == {
  900.                     echo '</tr>';
  901.                 }
  902.  
  903.                 $i++;
  904.             }
  905.  
  906.             // this is required to output a final closing </tr> tag when the number of items does not fully
  907.             // fill the last row of output - a blank column is left
  908.             if $intro $columns {
  909.                 echo '</tr>';
  910.             }
  911.  
  912.             echo '</table>';
  913.             echo '</td>';
  914.             echo '</tr>';
  915.         }
  916.  
  917.         // Links output
  918.         if $links && $i $total )  ) {
  919.             echo '<tr>';
  920.             echo '<td valign="top">';
  921.             echo '<div class="blog_more'$params->get'pageclass_sfx' .'">';
  922.             HTML_content::showLinks$rows$links$total$i1$ItemidCount );
  923.             echo '</div>';
  924.             echo '</td>';
  925.             echo '</tr>';
  926.         }
  927.  
  928.         // Pagination output
  929.         if $pagination {
  930.             if ( ( $pagination == && $total <= $limit ) ) {
  931.                 // not visible when they is no 'other' pages to display
  932.             else {
  933.                 // get the total number of records
  934.                 $limitstart $limitstart $limitstart 0;
  935.                 require_once$GLOBALS['mosConfig_absolute_path''/includes/pageNavigation.php' );
  936.                 $pageNav new mosPageNav$total$limitstart$limit );
  937.                 if $option == 'com_frontpage' {
  938.                     $link 'index.php?option=com_frontpage&amp;Itemid='$Itemid;
  939.                 else if $archive {
  940.                     $year $params->get'year' );
  941.                     $month $params->get'month' );
  942.                     $link 'index.php?option=com_content&amp;task='$task .'&amp;id='$id .'&amp;Itemid='$Itemid.'&amp;year='$year .'&amp;month='$month;
  943.                 else {
  944.                     $link 'index.php?option=com_content&amp;task='$task .'&amp;id='$id .'&amp;Itemid='$Itemid;
  945.                 }
  946.                 echo '<tr>';
  947.                 echo '<td valign="top" align="center">';
  948.                 echo $pageNav->writePagesLinks$link );
  949.                 echo '<br /><br />';
  950.                 echo '</td>';
  951.                 echo '</tr>';
  952.                 if $pagination_results {
  953.                     echo '<tr>';
  954.                     echo '<td valign="top" align="center">';
  955.                     echo $pageNav->writePagesCounter();
  956.                     echo '</td>';
  957.                     echo '</tr>';
  958.                 }
  959.             }
  960.         }
  961.  
  962.         echo '</table>';
  963.  
  964.     else if $archive && !$total {
  965.         // Search Failure message for Archives
  966.         $msg sprintfT_('There are no Archived entries for %s %s')Convertnumber2farsi($params->get'month' ))Convertnumber2farsi($params->get'year' )) );
  967.         echo '<br /><br /><div align="center">'$msg .'</div><br />';
  968.     else {
  969.         // Generic blog empty display
  970.         echo T_('There are no items to display');
  971.     }
  972.  
  973.     // Back Button
  974.     $params->set'back_button'$back );
  975.     mosHTML::BackButton $params );
  976. }
  977.  
  978.  
  979. function showItem$uid$gid&$access$pop$option$now {
  980.     global $database$mainframe;
  981.     global $mosConfig_offset$mosConfig_live_site$mosConfig_MetaTitle$mosConfig_MetaAuthor;
  982.  
  983.     if $access->canEdit {
  984.         $xwhere='';
  985.     else {
  986.         $xwhere "AND (a.state = '1' OR a.state = '-1')"
  987.         . "\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
  988.         . "\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
  989.         ;
  990.     }
  991.  
  992.     global $acl;
  993.     $viewAccess ($gid >= $acl->get_group_id'Registered''ARO' 0($gid >= $acl->get_group_id'Author''ARO' 0);
  994.     $query "SELECT a.*, ROUND(v.rating_sum/v.rating_count) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, s.name AS section, g.name AS groups"
  995.     . "\n FROM #__content AS a"
  996.     . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
  997.     . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'"
  998.     . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  999.     . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id"
  1000.     . "\n LEFT JOIN #__groups AS g ON a.access = g.id"
  1001.     . "\n WHERE a.id='"$uid ."' "$xwhere
  1002.     . "\n AND a.access <= "$viewAccess
  1003.     ;
  1004.     $database->setQuery$query );
  1005.     $row new mosExtendedContent();
  1006.  
  1007.     if $database->loadObject$row ) ) {
  1008.         $pathway =mosPathway::getInstance();
  1009.         $pathway->addItem($row->categorycategoryURL($row->sectionid$row->catid));
  1010.         $pathway->addItem($row->title'');
  1011.         $params =new mosParameters$row->attribs );
  1012.         $params->set'intro_only');
  1013.         $params->def'back_button'$mainframe->getCfg'back_button' ) );
  1014.         if $row->sectionid == 0{
  1015.             $params->set'item_navigation');
  1016.         else {
  1017.             $params->set'item_navigation'$mainframe->getCfg'item_navigation' ) );
  1018.         }
  1019.         // loads the links for Next & Previous Button
  1020.         if $params->get'item_navigation' ) ) {
  1021.             $query "SELECT a.id"
  1022.             . "\n FROM #__content AS a"
  1023.             . "\n WHERE a.catid = "$row->catid.""
  1024.             . "\n AND a.state = $row->state AND ordering < $row->ordering"
  1025.             . ($access->canEdit "" "\n AND a.access <= '"$gid ."'" )
  1026.             . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '"$now ."' )"
  1027.             . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '"$now ."' )"
  1028.             . "\n ORDER BY a.ordering DESC"
  1029.             . "\n LIMIT 1"
  1030.             ;
  1031.             $database->setQuery$query );
  1032.             $row->prev = $database->loadResult();
  1033.  
  1034.             $query "SELECT a.id"
  1035.             . "\n FROM #__content AS a"
  1036.             . "\n WHERE a.catid = "$row->catid.""
  1037.             . "\n AND a.state = $row->state AND ordering > $row->ordering"
  1038.             . ($access->canEdit "" "\n AND a.access <= '"$gid ."'" )
  1039.             . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '"$now ."' )"
  1040.             . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '"$now ."' )"
  1041.             . "\n ORDER BY a.ordering"
  1042.             . "\n LIMIT 1"
  1043.             ;
  1044.             $database->setQuery$query );
  1045.             $row->next = $database->loadResult();
  1046.         }
  1047.         // page title
  1048.         $mainframe->setPageTitle$row->title );
  1049.         if ($mosConfig_MetaTitle=='1'{
  1050.             $mainframe->addMetaTag'title' $row->title );
  1051.         }
  1052.         if ($mosConfig_MetaAuthor=='1'{
  1053.             $mainframe->addMetaTag'author' $row->author );
  1054.         }
  1055.  
  1056.         show$row$params$gid$access$pop$option );
  1057.     else {
  1058.         mosNotAuth();
  1059.         return;
  1060.     }
  1061. }
  1062.  
  1063.  
  1064. function show$row$params$gid&$access$pop$option$ItemidCount=NULL {
  1065.     global $database$mainframe$Itemid;
  1066.     global $mosConfig_live_site$mosConfig_absolute_path;
  1067.     global $options$cache;
  1068.  
  1069.     $noauth !$mainframe->getCfg'shownoauth' );
  1070.  
  1071.     if $access->canEdit {
  1072.         if $row->id === null || $row->access $gid {
  1073.             mosNotAuth();
  1074.             return;
  1075.         }
  1076.     else {
  1077.         if $row->id === null || $row->state == {
  1078.             mosNotAuth();
  1079.             return;
  1080.         }
  1081.         if $row->access $gid {
  1082.             if $noauth {
  1083.                 mosNotAuth();
  1084.                 return;
  1085.             else {
  1086.                 if !$params->get'intro_only' ) ) ) {
  1087.                     mosNotAuth();
  1088.                     return;
  1089.                 }
  1090.             }
  1091.         }
  1092.     }
  1093.  
  1094.     // GC Parameters
  1095.     $params->def'link_titles'$mainframe->getCfg'link_titles' ) );
  1096.     $params->def'author'!$mainframe->getCfg'hideAuthor' ) );
  1097.     $params->def'createdate'!$mainframe->getCfg'hideCreateDate' ) );
  1098.     $params->def'modifydate'!$mainframe->getCfg'hideModifyDate' ) );
  1099.     $params->def'print'!$mainframe->getCfg'hidePrint' ) );
  1100.     $params->def'pdf'!$mainframe->getCfg'hidePdf' ) );
  1101.     $params->def'email'!$mainframe->getCfg'hideEmail' ) );
  1102.     $params->def'rating'$mainframe->getCfg'vote' ) );
  1103.     $params->def'icons'$mainframe->getCfg'icons' ) );
  1104.     $params->def'readmore'$mainframe->getCfg'readmore' ) );
  1105.     // Other Params
  1106.     $params->def'image');
  1107.     $params->def'section');
  1108.     $params->def'section_link');
  1109.     $params->def'category');
  1110.     $params->def'category_link');
  1111.     $params->def'introtext');
  1112.     $params->def'pageclass_sfx''' );
  1113.     $params->def'item_title');
  1114.     $params->def'url');
  1115.  
  1116.     // loads the link for Section name
  1117.     if $params->get'section_link' ) ) {
  1118.         $query =     "SELECT a.id"
  1119.         . "\n FROM #__menu AS a"
  1120.         . "\n WHERE a.componentid = '"$row->sectionid."'"
  1121.         . "\n AND a.type = 'content_section'"
  1122.         . "\n AND a.published = 1"
  1123.         ;
  1124.         $database->setQuery$query );
  1125.         $_Itemid $database->loadResult();
  1126.         if (!intval($_Itemid))
  1127.                 $_Itemid intval($Itemidintval($Itemid1;
  1128.         $link sefRelToAbs'index.php?option=com_content&amp;task=section&amp;id='$row->sectionid .'&amp;Itemid='.$_Itemid );
  1129.         $row->section '<a href="'$link .'">'$row->section .'</a>';
  1130.     }
  1131.  
  1132.     // loads the link for Category name
  1133.     if $params->get'category_link' ) ) {
  1134.         $query =     "SELECT a.id"
  1135.         . "\n FROM #__menu AS a"
  1136.         . "\n WHERE a.componentid = "$row->catid.""
  1137.         . "\n AND a.type = 'content_category'"
  1138.         . "\n AND a.published = 1"
  1139.         ;
  1140.         $database->setQuery$query );
  1141.         $_Itemid $database->loadResult();
  1142.         if (!intval($_Itemid))
  1143.                 $_Itemid intval($Itemidintval($Itemid1;
  1144.         $link sefRelToAbs'index.php?option=com_content&amp;task=section&amp;id='$row->sectionid .'&amp;Itemid='.$_Itemid );
  1145.         $link sefRelToAbs'index.php?option=com_content&amp;task=category&amp;sectionid='$row->sectionid .'&amp;id='$row->catid .'&amp;Itemid='.$_Itemid );
  1146.         $row->category '<a href="'$link .'">'$row->category .'</a>';
  1147.     }
  1148.  
  1149.     // loads current template for the pop-up window
  1150.     $template '';
  1151.     if $pop {
  1152.         $params->set'popup');
  1153.         $database->setQuery"SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" );
  1154.         $template $database->loadResult();
  1155.     }
  1156.  
  1157.     // show/hides the intro text
  1158.     if $params->get'introtext'  ) ) {
  1159.         $row->text $row->introtext$params->get'intro_only' '' chr(13chr(13$row->fulltext);
  1160.     else {
  1161.         $row->text $row->fulltext;
  1162.     }
  1163.  
  1164.     // deal with the {mospagebreak} mambots
  1165.     // only permitted in the full text area
  1166.     $page intvalmosGetParam$_REQUEST'limitstart') );
  1167.  
  1168.     // record the hit
  1169.     if !$params->get'intro_only' ) ) {
  1170.         $obj new mosContent$database );
  1171.         $obj->hit$row->id );
  1172.     }
  1173.  
  1174.     $cache->call'HTML_content::show'$row$params$access$page$option$ItemidCount );
  1175. }
  1176.  
  1177.  
  1178. function editItem$uid$gid&$access$sectionid=0$task$Itemid ){
  1179.     global $database$mainframe$my;
  1180.     global $mosConfig_absolute_path$mosConfig_live_site$mosConfig_offset;
  1181.  
  1182.     $row new mosContent$database );
  1183.     // load the row from the db table
  1184.     $row->load$uid );
  1185.  
  1186.     // fail if checked out not by 'me'
  1187.     if $row->checked_out && $row->checked_out <> $my->id {
  1188.         echo"<script>alert('".sprintf(T_('The module [ %s ] is currently being edited by another person.')$row->title)."'); window.history.go(-1); </script>";
  1189.         exit;
  1190.     }
  1191.  
  1192.     if $uid {
  1193.         // existing record
  1194.         if !$access->canEdit || $access->canEditOwn && $row->created_by == $my->id ) ) ) {
  1195.             mosNotAuth();
  1196.             return;
  1197.         }
  1198.     else {
  1199.         // new record
  1200.         if (!($access->canEdit || $access->canEditOwn)) {
  1201.             mosNotAuth();
  1202.             return;
  1203.         }
  1204.     }
  1205.  
  1206.     if $uid {
  1207.         $sectionid $row->sectionid;
  1208.     }
  1209.  
  1210.     $lists array();
  1211.  
  1212.     // get the type name - which is a special category
  1213.     $query "SELECT name FROM #__sections WHERE id='$sectionid'";
  1214.     $database->setQuery$query );
  1215.     $section $database->loadResult();
  1216.  
  1217.     if $uid == {
  1218.         $row->catid 0;
  1219.     }
  1220.  
  1221.     if $uid {
  1222.         $row->checkout$my->id );
  1223.         if (trim$row->publish_down == "0000-00-00 00:00:00"{
  1224.             //$row->publish_down = 'Never';
  1225.             $row->publish_down     T_('Never');
  1226.         }else{
  1227.             $row->publish_down mosFormatDate$row->publish_up'QY-m-d H:i:s' );
  1228.         }
  1229.         
  1230.         $row->created         mosFormatDate$row->created'QY-m-d H:i:s' );
  1231.         $row->modified         mosFormatDate$row->modified'QY-m-d H:i:s' );
  1232.         $row->publish_up     mosFormatDate$row->publish_up'QY-m-d H:i:s' );
  1233.         
  1234.         if (trim$row->images )) {
  1235.             $row->images explode"\n"$row->images );
  1236.         else {
  1237.             $row->images array();
  1238.         }
  1239.         $query "SELECT name from #__users"
  1240.         . "\n WHERE id = "$row->created_by
  1241.         ;
  1242.         $database->setQuery$query    );
  1243.         $row->creator $database->loadResult();
  1244.  
  1245.         $query "SELECT name from #__users"
  1246.         . "\n WHERE id = "$row->modified_by
  1247.         ;
  1248.         $database->setQuery$query );
  1249.         $row->modifier $database->loadResult();
  1250.  
  1251.         $query "SELECT content_id from #__content_frontpage"
  1252.         ."\n WHERE content_id = "$row->id
  1253.         ;
  1254.         $database->setQuery$query );
  1255.         $row->frontpage = $database->loadResult();
  1256.     else {
  1257.         $row->sectionid     $sectionid;
  1258.         $row->version         0;
  1259.         $row->state         0;
  1260.         $row->ordering         0;
  1261.         $row->images         array();
  1262.         //$row->publish_up     = mosFormatDate( time(), 'Y-m-d' );
  1263.         $row->publish_up     jdate"d-m-Y"time($mosConfig_offset 60 60 );
  1264.         //$row->publish_down     = 'Never';
  1265.         $row->publish_down     T_('Never');
  1266.         $row->creator         0;
  1267.         $row->modifier         0;
  1268.         $row->frontpage     = 0;
  1269.     }
  1270.  
  1271.     // calls function to read image from directory
  1272.     $pathA         $mosConfig_absolute_path .'/images/stories';
  1273.     $pathL         $mosConfig_live_site .'/images/stories';
  1274.     $images     array();
  1275.     $folders     array();
  1276.     $folders[]     mosHTML::makeOption'/' );
  1277.     require_once($mosConfig_absolute_path.'/administrator/includes/mosAdminMenus.php');
  1278.     mosAdminMenus::ReadImages$pathA'/'$folders$images );
  1279.     // list of folders in images/stories/
  1280.     $lists['folders']         mosAdminMenus::GetImageFolders$folders$pathL );
  1281.     // list of images in specfic folder in images/stories/
  1282.     $lists['imagefiles']    mosAdminMenus::GetImages$images$pathL );
  1283.     // list of saved images
  1284.     $lists['imagelist']     mosAdminMenus::GetSavedImages$row$pathL );
  1285.  
  1286.     // make the select list for the states
  1287.     $states[mosHTML::makeOption0T_('Unpublished') );
  1288.     $states[mosHTML::makeOption1T_('Published') );
  1289.     $lists['state'mosHTML::selectList$states'state''class="inputbox" size="1"''value''text'intval$row->state ) );
  1290.  
  1291.     // build the html select list for ordering
  1292.     $query "SELECT ordering AS value, title AS text"
  1293.     . "\n FROM #__content"
  1294.     . "\n WHERE catid = '$row->catid'"
  1295.     . "\n ORDER BY ordering"
  1296.     ;
  1297.     $lists['ordering']         mosAdminMenus::SpecificOrdering$row$uid$query);
  1298.     // build list of categories
  1299.     $lists['catid']         mosAdminMenus::ComponentCategory'catid'$sectionidintval$row->catid ) );
  1300.     // build the select list for the image positions
  1301.     $lists['_align']         mosAdminMenus::Positions'_align' );
  1302.     // build the html select list for the group access
  1303.     $lists['access']         mosAdminMenus::Access$row );
  1304.  
  1305.     HTML_content::editContent$row$section$lists$images$access$my->id$sectionid$task$Itemid );
  1306. }
  1307.  
  1308.  
  1309. /**
  1310. * Saves the content item an edit form submit
  1311. */
  1312. function saveContent&$access {
  1313.     global $database$mainframe$my;
  1314.     global $mosConfig_absolute_path;
  1315.  
  1316.     $row new mosContent$database );
  1317.     if !$row->bind$_POST ) ) {
  1318.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  1319.         exit();
  1320.     }
  1321.     // sanitize
  1322.     $row->id intval($row->id);
  1323.     $row->catid intval($row->catid);
  1324.     $row->sectionid intval($row->sectionid);
  1325.     $isNew $row->id 1;
  1326.     if $isNew {
  1327.         // new record
  1328.         if !$access->canEdit || $access->canEditOwn ) ) {
  1329.             mosNotAuth();
  1330.             return;
  1331.         }
  1332.         $row->created date'Y-m-d H:i:s' );
  1333.         $row->created_by $my->id;
  1334.     else {
  1335.         // existing record
  1336.         if !$access->canEdit || $access->canEditOwn && $row->created_by == $my->id ) ) ) {
  1337.             mosNotAuth();
  1338.             return;
  1339.         }
  1340.         $row->modified date'Y-m-d H:i:s' );
  1341.         $row->modified_by $my->id;
  1342.     }
  1343.     //if ( trim( $row->publish_down ) == 'Never' ) {
  1344.     if trim$row->publish_down == T_('Never')  ) {
  1345.         $row->publish_down '0000-00-00 00:00:00';
  1346.     }else{
  1347.         $row->publish_down date('Y-m-d H:i:s'mlj($row->publish_down) );
  1348.     }
  1349.     $row->publish_up date('Y-m-d H:i:s'mlj($row->publish_up) );
  1350.     if (!$row->check()) {
  1351.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  1352.         exit();
  1353.     }
  1354.     $row->version++;
  1355.     if (!$row->store()) {
  1356.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  1357.         exit();
  1358.     }
  1359.  
  1360.     // manage frontpage items
  1361.     require_once$mainframe->getPath'class''com_frontpage' ) );
  1362.     $fp new mosFrontPage$database );
  1363.  
  1364.     if mosGetParam$_REQUEST'frontpage') ) {
  1365.  
  1366.         // toggles go to first place
  1367.         if (!$fp->load$row->id )) {
  1368.             // new entry
  1369.             $database->setQuery"INSERT INTO #__content_frontpage VALUES ('$row->id','1'));
  1370.             if (!$database->query()) {
  1371.                 echo "<script> alert('".$database->stderr()."');</script>\n";
  1372.                 exit();
  1373.             }
  1374.             $fp->ordering 1;
  1375.         }
  1376.     else {
  1377.         // no frontpage mask
  1378.         if !$fp->delete$row->id ) ) {
  1379.             $msg .= $fp->stderr();
  1380.         }
  1381.         $fp->ordering 0;
  1382.     }
  1383.     $fp->updateOrder();
  1384.  
  1385.     $row->checkin();
  1386.     $row->updateOrder"catid='$row->catid');
  1387.  
  1388.     // gets section name of item
  1389.     $database->setQuery"SELECT s.title"
  1390.     . "\n FROM #__sections AS s"
  1391.     . "\n WHERE s.scope = 'content'"
  1392.     . "\n AND s.id = '"$row->sectionid ."'"
  1393.     );
  1394.     // gets category name of item
  1395.     $section $database->loadResult();
  1396.     $database->setQuery"SELECT c.title"
  1397.     . "\n FROM #__categories AS c"
  1398.     . "\n WHERE c.id = '"$row->catid ."'"
  1399.     );
  1400.     $category $database->loadResult();
  1401.  
  1402.     if $isNew {
  1403.         // messaging for new items
  1404.         require_once$mosConfig_absolute_path .'/components/com_messages/messages.class.php' );
  1405.         $database->setQuery"SELECT id FROM #__users WHERE sendEmail = '1'" );
  1406.         $users $database->loadResultArray();
  1407.         if ($users{
  1408.             foreach ($users as $user_id{
  1409.                 $msg new mosMessage$database );
  1410.                 $msg->send$my->id$user_idT_("New Item")sprintfT_('A new content item has been submitted by [ %s ]  titled [ %s ]  from section [ %s ]  and category  [ %s ]')$my->username$row->title$section$category ) );
  1411.             }
  1412.         }
  1413.     }
  1414.      $Itemid     mosGetParam$_POST'Returnid''0' );
  1415.      $msg     $isNew T_('Thanks for your submission; it will be reviewed before being posted to the site.'T_('Item saved successfully.');
  1416.     mosRedirect'index.php'$msg );
  1417. }
  1418.  
  1419.  
  1420. /**
  1421. * Cancels an edit operation
  1422. @param database A database connector object
  1423. */
  1424. function cancelContent&$access {
  1425.     global $database$mainframe$my;
  1426.  
  1427.     $row new mosContent$database );
  1428.     $row->bind$_POST );
  1429.     // sanitize
  1430.     $row->id intval($row->id);
  1431.  
  1432.     if $access->canEdit || $access->canEditOwn && $row->created_by == $my->id ) ) {
  1433.         $row->checkin();
  1434.     }
  1435.  
  1436.     $Itemid mosGetParam$_POST'Returnid''0' );
  1437.  
  1438.     mosRedirect'index.php' );
  1439. }
  1440.  
  1441. /**
  1442. * Shows the email form for a given content item.
  1443. */
  1444. function emailContentForm$uid {
  1445.     global $database$mainframe$my;
  1446.     $row new mosContent$database );
  1447.     $row->load$uid );
  1448.  
  1449.     if $row->id === null || $row->access $my->gid {
  1450.         mosNotAuth();
  1451.         return;
  1452.     else {
  1453.         $template='';
  1454.         $database->setQuery"SELECT template FROM #__templates_menu WHERE client_id = '0' AND menuid = '0'" );
  1455.         $template $database->loadResult();
  1456.         HTML_content::emailForm$row->id$row->title$template );
  1457.     }
  1458.  
  1459. }
  1460.  
  1461.  
  1462. /**
  1463. * Shows the email form for a given content item.
  1464. */
  1465. function emailContentSend$uid {
  1466.     global $database$mainframe;
  1467.     global $mosConfig_live_site$mosConfig_sitename;
  1468.     global $mosConfig_mailfrom$mosConfig_fromname;
  1469.  
  1470.     $_Itemid $mainframe->getItemid$uid00  );
  1471.  
  1472.     $email trimmosGetParam$_POST'email''' ) );
  1473.     $yourname trimmosGetParam$_POST'yourname''' ) );
  1474.     $youremail trimmosGetParam$_POST'youremail''' ) );
  1475.     $subject_default sprintf(T_('Item sent by %s')$yourname);
  1476.     $subject trimmosGetParam$_POST'subject'$subject_default ) );
  1477.     
  1478.     session_start();
  1479.     $form_check mosGetParam$_POST'form_check''' );
  1480.     if (empty($_SESSION['_form_check_']['com_content']|| $form_check != $_SESSION['_form_check_']['com_content']{
  1481.       // the form hasn't been generated by the server on this session
  1482.        exit;
  1483.     }
  1484.     if !$email || !$youremail || is_email$email == false || is_email$youremail == false ) ) {
  1485.         echo "<script>alert (\"".T_('You must enter valid e-mail addresses for both yourself and your recipient.')."\"); window.history.go(-1);</script>";
  1486.         exit(0);
  1487.     }
  1488.  
  1489.     $template='';
  1490.     $database->setQuery"SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" );
  1491.     $template $database->loadResult();
  1492.  
  1493.     // link sent in email
  1494.     $link sefRelToAbs$mosConfig_live_site .'/index.php?option=com_content&task=view&id='$uid .'&Itemid='$_Itemid );
  1495.     // message text
  1496.     $msg sprintfT_(' The following page from the \"%s\" website has been sent to you by %s ( %s ).\n\nYou can access it at the following url:\n%s')$mosConfig_sitename$yourname$youremail$link );
  1497.  
  1498.     // mail function
  1499.     mosMail$mosConfig_mailfrom$mosConfig_fromname$email$subject$msg );
  1500.  
  1501.     HTML_content::emailSent$email$template );
  1502. }
  1503.  
  1504. function is_email$email ){
  1505.     $rBool false;
  1506.  
  1507.     if preg_match"/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/"$email ) ) {
  1508.         $rBool true;
  1509.     }
  1510.     return $rBool;
  1511. }
  1512.  
  1513. function recordVote({
  1514.     global $database;
  1515.  
  1516.     $user_rating mosGetParam$_REQUEST'user_rating');
  1517.     $url mosGetParam$_REQUEST'url''' );
  1518.     $cid mosGetParam$_REQUEST'cid');
  1519.     $cid intval$cid );
  1520.     $user_rating intval$user_rating );
  1521.  
  1522.     if ( ( $user_rating >= and $user_rating <= ) ) {
  1523.         $currip getenv'REMOTE_ADDR' );
  1524.  
  1525.         $query "SELECT * FROM #__content_rating WHERE content_id = $cid";
  1526.         $database->setQuery$query );
  1527.         $votesdb NULL;
  1528.         if !$database->loadObject$votesdb ) ) ) {
  1529.             $query "INSERT INTO #__content_rating ( content_id, lastip, rating_sum, rating_count )"
  1530.             . "\n VALUES ( '$cid', '$currip', '$user_rating', '1' )";
  1531.             $database->setQuery$query );
  1532.             $database->query(or die$database->stderr() );;
  1533.         else {
  1534.             if ($currip <> ($votesdb->lastip)) {
  1535.                 $query "UPDATE #__content_rating"
  1536.                 . "\n SET rating_count = rating_count + 1,"
  1537.                 . "\n rating_sum = rating_sum + $user_rating,"
  1538.                 . "\n lastip = '$currip'"
  1539.                 . "\n WHERE content_id = "$cid
  1540.                 ;
  1541.                 $database->setQuery$query );
  1542.                 $database->query(or die$database->stderr() );
  1543.             else {
  1544.                 mosRedirect $urlT_('You already voted for this poll today!') );
  1545.             }
  1546.         }
  1547.         mosRedirect $urlT_('Thanks for your vote!') );
  1548.     }
  1549. }
  1550.  
  1551.  
  1552. function _orderby_pri$orderby {
  1553.     switch $orderby {
  1554.         case 'alpha':
  1555.             $orderby 'cc.title, ';
  1556.             break;
  1557.         case 'ralpha':
  1558.             $orderby 'cc.title DESC, ';
  1559.             break;
  1560.         case 'order':
  1561.             $orderby 'cc.ordering, ';
  1562.             break;
  1563.         default:
  1564.             $orderby '';
  1565.             break;
  1566.     }
  1567.  
  1568.     return $orderby;
  1569. }
  1570.  
  1571.  
  1572. function _orderby_sec$orderby {
  1573.     switch $orderby {
  1574.         case 'date':
  1575.             $orderby 'a.created';
  1576.             break;
  1577.         case 'rdate':
  1578.             $orderby 'a.created DESC';
  1579.             break;
  1580.         case 'alpha':
  1581.             $orderby 'a.title';
  1582.             break;
  1583.         case 'ralpha':
  1584.             $orderby 'a.title DESC';
  1585.             break;
  1586.         case 'hits':
  1587.             $orderby 'a.hits DESC';
  1588.             break;
  1589.         case 'rhits':
  1590.             $orderby 'a.hits ASC';
  1591.             break;
  1592.         case 'order':
  1593.             $orderby 'a.ordering';
  1594.             break;
  1595.         case 'author':
  1596.             $orderby 'a.created_by, u.name';
  1597.             break;
  1598.         case 'rauthor':
  1599.             $orderby 'a.created_by DESC, u.name DESC';
  1600.             break;
  1601.         case 'front':
  1602.             $orderby 'f.ordering';
  1603.             break;
  1604.         default:
  1605.             $orderby 'a.ordering';
  1606.             break;
  1607.     }
  1608.  
  1609.     return $orderby;
  1610. }
  1611.  
  1612. /*
  1613. * @param int 0 = Archives, 1 = Section, 2 = Category
  1614. */
  1615. function _where$type=1&$access&$noauth$gid$id$now=NULL$year=NULL$month=NULL {
  1616.     $where array();
  1617.     
  1618.     // normal
  1619.     if $type 0{
  1620.         $where["a.state = '1'";
  1621.         if !$access->canEdit {
  1622.             $where["( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '"$now ."' )";
  1623.             $where["( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '"$now ."' )";
  1624.         }
  1625.         if $noauth {
  1626.             $where["a.access <= '"$gid ."'";
  1627.         }
  1628.         if $id {
  1629.             if $type == {
  1630.                 $where["a.sectionid IN ( "$id ." ) ";
  1631.             else if $type == {
  1632.                 $where["a.catid IN ( "$id ." ) ";
  1633.             }
  1634.         }
  1635.     }
  1636.  
  1637.     // archive
  1638.     if $type {
  1639.         // Jalali date to gregorian time
  1640.         $start_time mlj($year.'-'.$month.'-01');
  1641.         // Get start date for Query
  1642.         $start_date date("Y-m-d",$start_time);
  1643.         // days in this month
  1644.         $total_day jdate("t",$start_time);
  1645.         // Get end time
  1646.         $end_time mlj($year.'-'.$month.'-'.$total_day);
  1647.         // Get end date for query
  1648.         $end_date date("Y-m-d",$end_time);
  1649.         $where["a.state='-1'";
  1650.         $where["a.`created` >= '$start_date' AND a.`created` <= '$end_date'";
  1651.         if $noauth {
  1652.             $where["a.access <= '"$gid ."'";
  1653.         }
  1654.         if $id {
  1655.             if $type == -{
  1656.                 $where["a.sectionid = '"$id ."'";
  1657.             else if $type == -2{
  1658.                 $where["a.catid = '"$id ."'";
  1659.             }
  1660.         }
  1661.     }
  1662.  
  1663.     return $where;
  1664. }
  1665.  
  1666. function sectionURL ($sectionid{
  1667.     global $Itemid;
  1668.     return "index.php?option=com_content&task=section&id=$sectionid&Itemid=$Itemid";
  1669. }
  1670.  
  1671. function categoryURL ($sectionid$catid{
  1672.     global $Itemid;
  1673.     return "index.php?option=com_content&task=category&sectionid=$sectionid&id=$catid&Itemid=$Itemid";
  1674. }
  1675.  
  1676. ?>

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