PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_acymailing/classes/list.php

https://github.com/srgg6701/auction-ruseasons
PHP | 151 lines | 114 code | 30 blank | 7 comment | 20 complexity | f3f8a71398c91640f9773038b5182968 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, JSON
  1. <?php
  2. /**
  3. * @package AcyMailing for Joomla!
  4. * @version 4.1.0
  5. * @author acyba.com
  6. * @copyright (C) 2009-2013 ACYBA S.A.R.L. All rights reserved.
  7. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  8. */
  9. defined('_JEXEC') or die('Restricted access');
  10. ?><?php
  11. class listClass extends acymailingClass{
  12. var $tables = array('listsub','listcampaign','listmail','list');
  13. var $pkey = 'listid';
  14. var $namekey = 'alias';
  15. var $type = 'list';
  16. var $newlist = false;
  17. function getLists($index = ''){
  18. $query = 'SELECT * FROM '.acymailing_table('list').' WHERE type = \''.$this->type.'\' ORDER BY ordering ASC';
  19. $this->database->setQuery($query);
  20. return $this->database->loadObjectList($index);
  21. }
  22. function getFrontendLists($index = ''){
  23. $lists = $this->getLists($index);
  24. $copyAllLists = $lists;
  25. $my = JFactory::getUser();
  26. foreach($copyAllLists as $id => $oneList){
  27. if(!$oneList->published OR empty($my->id)){
  28. unset($lists[$id]);
  29. continue;
  30. }
  31. if((int)$my->id == (int)$oneList->userid) continue;
  32. if(!acymailing_isAllowed($oneList->access_manage)){
  33. unset($lists[$id]);
  34. continue;
  35. }
  36. }
  37. return $lists;
  38. }
  39. function get($listid,$default = null){
  40. $query = 'SELECT a.*, b.name as creatorname, b.username, b.email FROM '.acymailing_table('list').' as a LEFT JOIN '.acymailing_table('users',false).' as b on a.userid = b.id WHERE listid = '.intval($listid).' LIMIT 1';
  41. $this->database->setQuery($query);
  42. return $this->database->loadObject();
  43. }
  44. function saveForm(){
  45. $app = JFactory::getApplication();
  46. $list = new stdClass();
  47. $list->listid = acymailing_getCID('listid');
  48. $formData = JRequest::getVar( 'data', array(), '', 'array' );
  49. foreach($formData['list'] as $column => $value){
  50. if($app->isAdmin() OR $this->allowedField('list',$column)){
  51. acymailing_secureField($column);
  52. $list->$column = strip_tags($value);
  53. }
  54. }
  55. $list->description = JRequest::getVar('editor_description','','','string',JREQUEST_ALLOWRAW);
  56. $listid = $this->save($list);
  57. if(!$listid) return false;
  58. if(empty($list->listid)){
  59. $orderClass = acymailing_get('helper.order');
  60. $orderClass->pkey = 'listid';
  61. $orderClass->table = 'list';
  62. $orderClass->groupMap = 'type';
  63. $orderClass->groupVal = empty($list->type) ? $this->type : $list->type;
  64. $orderClass->reOrder();
  65. $this->newlist = true;
  66. }
  67. if(!empty($formData['listcampaign'])){
  68. $affectedLists = array();
  69. foreach($formData['listcampaign'] as $affectlistid => $receiveme){
  70. if(!empty($receiveme)){
  71. $affectedLists[] = $affectlistid;
  72. }
  73. }
  74. $listCampaignClass = acymailing_get('class.listcampaign');
  75. $listCampaignClass->save($listid,$affectedLists);
  76. }
  77. JRequest::setVar( 'listid', $listid);
  78. return true;
  79. }
  80. function save($list){
  81. if(empty($list->listid)){
  82. if(empty($list->userid)){
  83. $user = JFactory::getUser();
  84. $list->userid = $user->id;
  85. }
  86. if(empty($list->alias)) $list->alias = $list->name;
  87. }
  88. if(isset($list->alias)){
  89. if(empty($list->alias)) $list->alias = $list->name;
  90. $list->alias = JFilterOutput::stringURLSafe(trim($list->alias));
  91. }
  92. if(empty($list->listid)){
  93. $status = $this->database->insertObject(acymailing_table('list'),$list);
  94. }else{
  95. $status = $this->database->updateObject(acymailing_table('list'),$list,'listid');
  96. }
  97. if($status) return empty($list->listid) ? $this->database->insertid() : $list->listid;
  98. return false;
  99. }
  100. function onlyCurrentLanguage($lists){
  101. $currentLanguage = JFactory::getLanguage();
  102. $currentLang = strtolower($currentLanguage->getTag());
  103. $newLists = array();
  104. foreach($lists as $id => $oneList){
  105. if($oneList->languages == 'all' OR in_array($currentLang,explode(',',$oneList->languages))){
  106. $newLists[$id] = $oneList;
  107. }
  108. }
  109. return $newLists;
  110. }
  111. function onlyAllowedLists($lists){
  112. $my = JFactory::getUser();
  113. $newLists = array();
  114. foreach($lists as $id => $oneList){
  115. if(!$oneList->published) continue;
  116. if(!acymailing_isAllowed($oneList->access_sub)) continue;
  117. $newLists[$id] = $oneList;
  118. }
  119. return $newLists;
  120. }
  121. }