um); $Addr[] = sprintf("%s", $Postaddr); $Addr[] = sprintf("%s", $CountryName); } return $Addr; } public static function InvoiceAddresses($UserId = null){ $dbh = Database::getInstance(); $query = " SELECT `ID`, `Type`, `Default`, `Name`, `Addr1`, `Addr2`, `Postnum`, `Postaddr`, `Country`, `Email`, (SELECT `name` FROM `system_country` WHERE CONVERT(`iso_code` USING `utf8`) COLLATE `utf8_unicode_ci` = `Country`) `CountryName` FROM `school_user_addr` WHERE `UserId` = ? ORDER BY `ID` "; $pst = $dbh->prepare($query); $pst->execute(array($UserId)); if($pst->rowCount() === 0) return false; $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[$res['ID']] = array( "Type" => (int)$res['Type'], "Default" => (int)$res['Default'], "Name" => $res['Name'], "Addr1" => $res['Addr1'], "Addr2" => $res['Addr2'], "PostNum" => $res['Postnum'], "PostAddr" => $res['Postaddr'], "Country" => array("Iso" => $res['Country'], "Label" => $res['CountryName']), "Email" => $res['Email'] ); } return $Data; } public static function InvoiceDefault($UserId = null){ $dbh = Database::getInstance(); $query = " SELECT `ID`, `Type`, `Default`, `Name`, `Addr1`, `Addr2`, `Postnum`, `Postaddr`, `Country`, (SELECT `name` FROM `system_country` WHERE CONVERT(`iso_code` USING `utf8`) COLLATE `utf8_unicode_ci` = `Country`) `CountryName` FROM `school_user_addr` WHERE `UserId` = ? AND `Default` = 1 "; $pst = $dbh->prepare($query); $pst->execute(array($UserId)); if($pst->rowCount() === 0) return false; $res = $pst->fetch(PDO::FETCH_ASSOC); return array( "Type" => (int)$res['Type'], "Default" => (int)$res['Default'], "Name" => $res['Name'], "Addr1" => $res['Addr1'], "Addr2" => $res['Addr2'], "PostNo" => $res['Postnum'], "PostAddr" => $res['Postaddr'], "Country" => array("Iso" => $res['Country'], "Label" => $res['CountryName']) ); $pst = null; return false; } public static function Types(){ return [ 1 => [ 'Name' => _('Deltagare/person'), 'Desc' => _('Person som deltar i verksamheten.') ], 2 => [ 'Name' => _('Kund/förening'), 'Desc' => _('Kund/förening som kan faktureras via webbshop.') ], ]; } public static function Levels(){ return [ 0 => [ 'Name' => _('Deltagare/Ledare'), 'Desc' => _('Kan logga in på hemsidan, göra aktivitetsbokning mm. Aktiva ledare kan hantera sina aktiviteter/tillfällen.') ], // 1 => [ 'Name' => _('Ledare'), 'Desc' => _('Åtkomst till ledarsidorna / närvarorapportering mm.') ], 2 => [ 'Name' => _('Administratör'), 'Desc' => _('Åtkomst till administrationen.') ], ]; } public static function Level($Level){ switch($Level){ case 2 : return _("Administratör"); break; case 1 : return _("Ledare"); default : return _("Deltagare"); } } public static function LastVisit($UserId){ $dbh = Database::getInstance(); $query = " SELECT `log_datetime` `LV` FROM `school_user_log` WHERE `log_action` = 2 AND `log_user` = :UserId ORDER BY `log_datetime` DESC LIMIT 2 "; $pst = $dbh->prepare($query); $pst->bindParam(":UserId", $UserId, PDO::PARAM_INT); $pst->execute(); if($pst->rowCount() === 0) return false; // echo sprintf("
%s
", print_r($pst->fetchAll(PDO::FETCH_ASSOC), true)); // exit; $R = $pst->fetchAll(PDO::FETCH_NUM); $L = end($R); // echo sprintf("
%s
", print_r($, true)); // exit; return strftime(DATE_DAY_MONTH_YEAR_HOUR_MINUTE, $L[0]); } /* get user info -------------------------------------------------------------*/ public static function GetUserInfo($UserId = null){ global $__AbsUrl; $dbh = Database::getInstance(); $query = " SELECT `user_id`, `user_pers_number`, `user_name`, `user_type`, `user_group`, `user_level`, `user_mem_num`, `user_lic_num`, `user_firstname`, `user_lastname`, DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(`user_birthdate`)), '%Y')+0 AS age, `user_birthdate`, `user_gender`, `user_phone1`, `usereadmore}} {{{ text_ext }}} {{/readmore}} {{#social}}
{{#facebook_simple}} Dela {{/facebook_simple}} {{#facebook}}


{{/facebook}} {{#twitter}} {{/twitter}}
{{/social}} {{#readmore}}
{{i18n.readmore}}
{{/readmore}}
{{/newslist}} EOT; public $template_single = <<
{{#event_date}} {{/event_date}} {{^event_date}} {{/event_date}}
{{#image}}

image: {{title}}

{{/image}} {{#show_excerpt}}
{{/show_excerpt}}{{{ text }}}{{#show_excerpt}}
{{/show_excerpt}} {{^readmore}} {{{ text_ext }}} {{/readmore}}
{{#social}}
{{#facebook_simple}} Dela {{/facebook_simple}} {{#facebook}}


{{/facebook}} {{#twitter}} {{/twitter}}
{{/social}} {{#readmore}}
{{i18n.readmore}}
{{/readmore}}
{{/newslist}} EOT; public $template_archive = << {{#recent_has_items}} {{/recent_has_items}} {{#history_has_items}}
{{/history_has_items}} EOT; function __construct(){ $this->dbh = Database::getInstance(); $query = "SELECT `config_key`, `config_value` FROM `system_config` WHERE `config_key` IN('SOCIAL_TWITTER','SOCIAL_FACEBOOK','FACEBOOK_APP_ID')"; foreach($this->dbh->query($query, PDO::FETCH_ASSOC) as $res){ if($res['config_key'] === 'SOCIAL_TWITTER' && (int)$res['config_value'] === 1){ $this->twitter = 1; }elseif($res['config_key'] === 'SOCIAL_FACEBOOK' && (int)$res['config_value'] === 1){ $this->facebook = 1; }elseif($res['config_key'] === 'FACEBOOK_APP_ID' && !is_null($res['config_value'])){ $this->facebook_app_id = 1; } } } private function tags_to_query($Tags){ $D = []; foreach($Tags as $T){ if((int)$T === 0) continue; $D[] = (int)$T; } return implode(',', $D); } public function get_tags($NewsId = 0){ $pst = $this->dbh->prepare(" SELECT `a`.`Name` FROM `site_news_tags` `a` INNER JOIN `site_news_tag` `b` ON `a`.`TagId` = `b`.`TagId` WHERE `b`.`NewsId` = ? ORDER BY CONVERT(`a`.`Name` USING `latin1`) COLLATE `latin1_swedish_ci` "); $pst->execute( [ $NewsId ] ); if($pst->rowCount() === 0) return false; $Data = []; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[] = $res['Name']; } $pst = null; return implode(', ', $Data); } public function all_tags(){ $query = " SELECT COUNT(`b`.`NewsId`) `Ant`, `a`.`TagId`, `a`.`Name` FROM `site_news_tags` `a` INNER JOIN `site_news_tag` `b` ON `a`.`TagId` = `b`.`TagId` "; if(!is_null($this->period)){ $query .= " INNER JOIN `site_news` ON `news_id` = `b`.`NewsId` WHERE DATE_FORMAT(`news_date`, '%Y-%m') = '{$this->period}' "; } $query .= " GROUP BY `b`.`TagId` ORDER BY CONVERT(`a`.`Name` USING `latin1`) COLLATE `latin1_swedish_ci` "; $result = mysql_query($query) or die((DEBUG ? sprintf('

%s

%s

%s
', _('Ett fel uppstod'), mysql_error(), str_replace("\t", "", $query)) : _('Ett fel uppstod, kontakta supporten.'))); if(mysql_num_rows($result) === 0) return false; $__CookieName = sprintf(NAME_NEWS_FILTER, $this->page_id); $Active = 0; if(isset($_COOKIE[$__CookieName])) $Active = (int)$_COOKIE[$__CookieName]; $Data = array(); while($res = mysql_fetch_assoc($result)){ $Data[] = array("Id" => (int)$res['TagId'], "Name" => $res['Name'], "Ant" => (int)$res['Ant'], "Active" => ((int)$res['TagId'] === $Active)); } mysql_free_result($result); return $Data; } public function news($Limit = 5){ global $__AbsUrl; $params = []; $conds = []; $query = " SELECT DISTINCT `news_id`, `news_type`, DATE_FORMAT(IF(`news_type` = 3, `news_date_event`, `news_date`), '%Y-%m') AS `Ym`, IF(`news_type` = 3, `news_date_event`, `news_date`) `news_date`, `news_date_unpublish`, `news_date_event`, UNIX_TIMESTAMP(`news_date_event`) `event_date`, `news_topic`, `news_text`, NULLIF(`news_text_ext`, NULL) `news_text_ext`, `news_picture` `news_image` FROM `site_news` "; if($this->id !== 0){ $params[] = $this->id; $conds[] = "`news_id` = ? "; }else{ if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ $query .= " LEFT JOIN `content_tag` ON `news_id` = `Parent` AND `Type` = 'news' "; }elseif(count($this->news_tags) !== 0){ $query .= " INNER JOIN `site_news_tag` ON `news_id` = `NewsId` "; } if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ if($this->section_id !== 0){ $params[] = $this->section_id; $conds[] = "`SectionId` = ? "; }else{ $conds[] = "(`SectionId` = 0 OR `SectionId` IS NULL) "; } }elseif(count($this->news_tags) !== 0){ $params = array_merge($params, $this->news_tags); $tags = implode(",", array_fill(0, (count($this->news_tags)), '?')); $conds[] = "`TagId` IN({$tags}) "; } $params[] = $this->language; $conds[] = "`Language` = ? "; $params[] = $this->important; $conds[] = "`news_important` = ? "; if(!is_null($this->period)){ $params[] = $this->period; $conds[] = "DATE_FORMAT(`news_date`, '%Y-%m') = ? "; } } $query .= "WHERE (`news_date` <= CURRENT_TIMESTAMP() AND NOT (`news_date_unpublish` IS NOT NULL AND `news_date_unpublish` <= CURRENT_TIMESTAMP()))\n"; if(true === $this->__IsAuthenticated){ if($this->id === 0) $conds[] = "`news_type` <> 3 "; }else{ if($this->id === 0){ $conds[] = "`news_type` = 1 "; } } foreach($conds as $c) $query .= sprintf("AND %s\n", $c); $query .= " ORDER BY `news_date` DESC "; if($Limit !== -1) $query .= sprintf("LIMIT %d", (int)$Limit); // echo sprintf("
%s\n%s
", var_export($params, true), str_replace("\t","",$query)); $pst = $this->dbh->prepare($query); foreach($params as $K => $P) $pst->bindValue(($K+1), $P); $pst->execute(); if($pst->rowCount() !== 0){ $i = 0; $Data = []; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Url = sprintf('%s%s/%d-%s/', $this->base_url, $res['Ym'], $res['news_id'], post_slug($res['news_topic'])); $Data[$i] = [ 'id' => (int)$res['news_id'], 'event' => ((int)$res['news_type'] === 3), 'private' => ((int)$res['news_type'] === 2), 'create_date' => strftime($this->date_format, strtotime($res['news_date'])), 'event_date' => $res['event_date'], 'event_time' => strftime(DATE_HOUR_MINUTE, $res['event_date']), 'event_month' => strftime(DATE_MONTH, $res['event_date']), 'event_day' => strftime(DATE_DAY, $res['event_date']), 'event_daymonthyear' => null, 'period' => strftime("%Y-%m", strtotime($res['news_date'])), 'period_label' => strftime(DATE_MONTH_YY, strtotime($res['news_date'])), 'title' => $res['news_topic'], 'shorttitle' => CropStr($res['news_topic'], 30), 'excerpt' => null, 'text' => $res['news_text'], 'text_ext' => $res['news_text_ext'], 'readmore' => (!is_null($res['news_text_ext']) && $this->id === 0), 'image' => null, 'url' => $Url, 'social' => [], 'tags' => $this->get_tags($res['news_id']), ]; if(!is_null($res['news_date_event'])){ $Data[$i]['event_daymonthyear'] = format_datetime(new DateTime($res['news_date_event']), "cccc dd MMMM yyyy"); } if(!is_null($res['news_image']) && file_exists(sprintf('%s%s', ROOTPATH, ltrim($res['news_image'],'/'))) === true) $Data[$i]['image'] = sprintf('%s%s', rtrim($__AbsUrl, '/'), $res['news_image']); if(strlen($res['news_text']) !== 0){ $Excerpt = strip_tags($res['news_text']); $Data[$i]['excerpt'] = CropStr($Excerpt, 100, ' '); } if($this->facebook_app_id === 1 && $this->facebook === 1 && (int)$res['news_type'] !== 2){ $Data[$i]['social']['facebook'] = $Url; }elseif($this->facebook_app_id === 0 && $this->facebook === 1 && (int)$res['news_type'] !== 2){ $Data[$i]['social']['facebook_simple'] = true; } if($this->twitter === 1 && (int)$res['news_type'] !== 2) $Data[$i]['social']['twitter'] = [ 'url' => urlencode($Url), 'title' => urlencode($res['news_topic']), 'tags' => urlencode(GLOBAL_PAGE_TITLE) ]; if(!$this->images) $Data[$i]['image'] = null; $i++; } return $Data; } $pst = null; return false; } public function events($Limit = 5){ global $__AbsUrl; $params = []; $query = " SELECT DISTINCT `news_id`, `news_type`, DATE_FORMAT(IF(`news_type` = 3, `news_date_event`, `news_date`), '%Y-%m') AS `Ym`, IF(`news_type` = 3, `news_date_event`, `news_date`) `news_date`, UNIX_TIMESTAMP(`news_date_event`) `event_date`, `news_topic`, `news_text`, NULLIF(`news_text_ext`, NULL) `news_text_ext`, `news_picture` `news_image` FROM `site_news` "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ $query .= " LEFT JOIN `content_tag` ON `news_id` = `Parent` AND `Type` = 'news' "; }elseif(count($this->news_tags) !== 0){ $query .= " INNER JOIN `site_news_tag` ON `news_id` = `NewsId` "; } $query .= " WHERE `news_type` = 3 "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ if($this->section_id !== 0){ $params[] = $this->section_id; $query .= " `SectionId` = ? "; }else{ $query .= " (`SectionId` = 0 OR `SectionId` IS NULL) "; } }elseif(count($this->news_tags) !== 0){ $params = array_merge($params, $this->news_tags); $tags = implode(",", array_fill(0, (count($this->news_tags)), '?')); $query .= "AND `TagId` IN({$tags}) "; } $params[] = $this->language; // // AND `news_important` = ? /* !! kontrollera widget händelser icke-viktiga !! */ $conds[] = "`Language` = ? "; if($this->is_widget === true){ $params[] = $this->important; $conds[] = "`news_important` = ? "; } if(!is_null($this->period)){ $params[] = $this->period; $conds[] = "DATE_FORMAT(`news_date_event`, '%Y-%m') = ? "; }else{ $conds[] = "`news_date_event` >= CURRENT_DATE() "; } foreach($conds as $c) $query .= sprintf("AND %s\n", $c); $query .= " AND (`news_date` <= CURRENT_TIMESTAMP() AND NOT (`news_date_unpublish` IS NOT NULL AND `news_date_unpublish` <= CURRENT_TIMESTAMP())) ORDER BY `news_date_event` "; if($Limit !== -1) $query .= sprintf("LIMIT %d", (int)$Limit); // echo sprintf("
%s\n%s
", var_export($params, true), str_replace("\t","",$query)); $pst = $this->dbh->prepare($query); foreach($params as $K => $P) $pst->bindValue(($K+1), $P); $pst->execute(); if($pst->rowCount() !== 0){ $i = 0; $Data = []; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Url = sprintf('%s%s/%d-%s/', $this->base_url, $res['Ym'], $res['news_id'], post_slug($res['news_topic'])); $Data[$i] = [ 'id' => (int)$res['news_id'], 'create_date' => strftime($this->date_format, $res['event_date']), 'create_time' => strftime(DATE_HOUR_MINUTE, $res['event_date']), 'event_date' => $res['event_date'], 'event_time' => strftime(DATE_HOUR_MINUTE, $res['event_date']), 'event_month' => strftime(DATE_MONTH, $res['event_date']), 'event_day' => strftime(DATE_DAY, $res['event_date']), 'period' => strftime("%Y-%b", strtotime($res['news_date'])), 'period_label' => strftime(DATE_MONTH_YY, strtotime($res['news_date'])), 'title' => $res['news_topic'], 'shorttitle' => CropStr($res['news_topic'], 30), 'excerpt' => null, 'text' => $res['news_text'], 'text_ext' => $res['news_text_ext'], 'readmore' => (!is_null($res['news_text_ext']) && $this->id === 0), 'image' => null, 'url' => $Url, 'social' => [], 'tags' => $this->get_tags($res['news_id']), ]; if(strlen($res['news_text']) !== 0){ $Excerpt = strip_tags($res['news_text']); $Data[$i]['excerpt'] = CropStr($Excerpt, 100, ' '); } if(!is_null($res['news_image']) && file_exists(sprintf('%s%s', ROOTPATH, ltrim($res['news_image'],'/'))) === true) $Data[$i]['image'] = sprintf('%s%s', rtrim($__AbsUrl, '/'), $res['news_image']); if($this->facebook === 1 && $this->facebook_app_id === 1 && (int)$res['news_type'] !== 2) $Data[$i]['social']['facebook'] = $Url; if($this->twitter === 1 && (int)$res['news_type'] !== 2) $Data[$i]['social']['twitter'] = [ 'url' => urlencode($Url), 'title' => urlencode($res['news_topic']), 'tags' => urlencode(GLOBAL_PAGE_TITLE) ]; if(!$this->images) $Data[$i]['image'] = null; $i++; } return $Data; } $pst = null; return false; } public function upcoming_events($Limit = 5){ $params = []; $Data = []; $i = 0; $query = " /* UPCOMING EVENTS */ SELECT DISTINCT `news_id`, DATE_FORMAT(`news_date`, '%Y-%m') AS `Ym`, `news_date_event`, `news_topic`, DATE_FORMAT(`news_date_event`, '%Y%m%d') AS `event_day`, UNIX_TIMESTAMP(`news_date_event`) `event_date` FROM site_news "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ $query .= " LEFT JOIN `content_tag` ON `news_id` = `Parent` AND `Type` = 'news' "; }elseif(count($this->news_tags) !== 0){ $query .= " INNER JOIN `site_news_tag` ON `news_id` = `NewsId` "; } $query .= " WHERE `Language` = ? "; $params[] = $this->language; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ if($this->section_id !== 0){ $params[] = $this->section_id; $query .= " AND `SectionId` = ? "; }else{ $query .= "AND (`SectionId` = 0 OR `SectionId` IS NULL) "; } }elseif(count($this->news_tags) !== 0){ $params = array_merge($params, $this->news_tags); $tags = implode(",", array_fill(0, (count($this->news_tags)), '?')); $query .= "AND `TagId` IN({$tags}) "; } $query .= " /*AND `news_important` = 0 */ AND `news_date_event` >= CURRENT_DATE() AND (`news_date` <= CURRENT_TIMESTAMP() AND NOT (`news_date_unpublish` IS NOT NULL AND `news_date_unpublish` <= CURRENT_TIMESTAMP())) /*AND `news_date_event` <= DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY) */ ORDER BY `news_date_event` ASC "; if($Limit !== -1) $query .= sprintf("LIMIT %d", $Limit); // echo sprintf("
%s\n%s
", var_export($params, true), str_replace("\t","",$query)); $pst = $this->dbh->prepare($query); foreach($params as $K => $P) $pst->bindValue(($K+1), $P); $pst->execute(); if($pst->rowCount() !== 0){ while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[$res['event_day']][] = [ 'id' => (int)$res['news_id'], // 'create_date' => $res['event_date'], 'create_time' => strftime(DATE_HOUR_MINUTE, $res['event_date']), 'event_date' => $res['event_date'], 'event_month' => strftime(DATE_MONTH, $res['event_date']), 'event_day' => strftime(DATE_DAY, $res['event_date']), 'title' => $res['news_topic'], 'url' => sprintf('%s%s/%d-%s/', $this->base_url, $res['Ym'], $res['news_id'], post_slug($res['news_topic'])) ]; $i++; } } $pst = null; $params = []; $query = " SELECT `comp_id`, `comp_name`, DATE_FORMAT(`comp_start`, '%Y-%m') AS `Ym`, DATE_FORMAT(`comp_start`, '%Y-%m-%d') AS `comp_start`, DATE_FORMAT(`comp_end`, '%Y-%m-%d') AS `comp_end`, DATE_FORMAT(`comp_start`, '%Y%m%d') AS `event_day`, CONCAT_WS(', ', `comp_hall`, `comp_city`) AS `Location`, UNIX_TIMESTAMP(`comp_start`) `event_date` FROM `competition` LEFT JOIN `content_tag` ON `comp_id` = `Parent` AND `Type` = 'comp' WHERE DATE_FORMAT(`comp_start`, '%Y-%m-%d') >= CURRENT_DATE() /*AND DATE_FORMAT(`comp_start`, '%Y-%m-%d') <= DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY) */ "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ if($this->section_id !== 0){ $params[] = $this->section_id; $query .= " AND `SectionId` = ? "; }else{ $query .= "AND (`SectionId` = 0 OR `SectionId` IS NULL)"; } }else{ $query .= "AND `SectionId` IS NULL"; } $query .= " AND `comp_removed` = 1 ORDER BY `comp_start` ASC "; // echo sprintf("
%s
", str_replace("\t","",$query)); $pst = $this->dbh->prepare($query); foreach($params as $K => $P) $pst->bindValue(($K+1), $P); $pst->execute(); if($pst->rowCount() !== 0){ while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[$res['event_day']][] = [ 'id' => (int)$res['comp_id'], 'event_date' => $res['event_date'], 'event_month' => strftime(DATE_MONTH, $res['event_date']), 'event_day' => strftime(DATE_DAY, $res['event_date']), 'title' => $res['comp_name'], 'url' => sprintf('%s%s%d-%s/', rtrim(ABSURL, '/'), $this->page_urls['Competition'], $res['comp_id'], post_slug($res['comp_name'])) ]; $i++; } } $pst = null; if(count($Data) === 0) return false; ksort($Data); if(count($Data) > $Limit) $Data = array_slice($Data, 0, $Limit, true); // echo sprintf("
%s
", var_export($Data, true)); $i = 0; $Obj = []; foreach($Data as $Date => $Item){ $Obj[$i] = [ 'date' => strftime($this->date_format, strtotime($Date)), 'events' => $Item ]; $i++; } return $Obj; } public function rss_feed($Limit = 30){ global $__AbsUrl; $__AbsUrl = trim($__AbsUrl, '/'); $Data = []; $params = [ ]; $query = " SELECT DISTINCT `news_id`, `news_type`, DATE_FORMAT(`news_date`, '%Y-%m') AS `Ym`, UNIX_TIMESTAMP(`news_date`) `news_date`, UNIX_TIMESTAMP(`news_date_event`) `event_date`, `news_topic`, `news_text`, NULLIF(`news_text_ext`, NULL) `news_text_ext`, `news_picture` `news_image` FROM `site_news` "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ $query .= " LEFT JOIN `content_tag` ON `news_id` = `Parent` AND `Type` = 'news' "; }elseif(count($this->news_tags) !== 0){ $query .= " INNER JOIN `site_news_tag` ON `news_id` = `NewsId` "; } $query .= " WHERE `news_type` = 1 "; if(true === defined("KANSLIETONLINE_MULTISITE") && true === KANSLIETONLINE_MULTISITE){ if($this->section_id !== 0){ $params[] = $this->section_id; $query .= " AND `SectionId` = ? "; }else{ $query .= "AND (`SectionId` = 0 OR `SectionId` IS NULL)"; } }elseif(count($this->news_tags) !== 0){ $params = array_merge($params, $this->news_tags); $tags = implode(",", array_fill(0, (count($this->news_tags)), '?')); $query .= "AND `TagId` IN({$tags}) "; } $params[] = $this->language; $query .= " AND `Language` = ? AND (`news_date` <= CURRENT_TIMESTAMP() AND NOT (`news_date_unpublish` IS NOT NULL AND `news_date_unpublish` <= CURRENT_TIMESTAMP())) ORDER BY `news_date` DESC LIMIT {$Limit} "; $pst = $this->dbh->prepare($query); foreach($params as $K => $P) $pst->bindValue(($K+1), $P); $pst->execute(); if($pst->rowCount() !== 0){ $i = 0; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[$i] = array( "Id" => (int)$res['news_id'], "Date" => (int)$res['news_date'], // "Title" => $res['news_topic'], "Title" => trim( htmlspecialchars( html_entity_decode( strip_tags( $res['news_topic'] ) ) ) ), "Slug" => sprintf("%d-%s", $res['news_id'], post_slug($res['news_topic'])), "Text" => strip_tags(preg_replace("/(src=\")(.*)(\/explorer)/", "$1http://example.com$3", $res['news_text']), ''), "Text" => trim( htmlspecialchars( html_entity_decode( preg_replace("/(src=\")(.*)(\/explorer)/", "$1$__AbsUrl$3", strip_tags( $res['news_text'], '' ) ) ) ) ), "Href" => sprintf('%s%s/%d-%s/', $this->base_url, $res['Ym'], $res['news_id'], post_slug($res['news_topic'])) ); $i++; } } $pst = null; return $Data; } public function archive2(){ $query = " SELECT COUNT(`news_id`) `Ant`, IF(`news_date_event` IS NULL, `news_date`, `news_date_event`) `date`, `news_date`, `news_date_event`, DATE_FORMAT(IF(`news_date_event` IS NULL, `news_date`, `news_date_event`), '%Y%m') `Ym`, DATE_FORMAT(IF(`news_date_event` IS NULL, `news_date`, `news_date_event`), '%Y') `Y`, DATE_FORMAT(IF(`news_date_event` IS NULL, `news_date`, `news_date_event`), '%m') `m` FROM `site_news` WHERE (`news_date` <= CURRENT_TIMESTAMP() AND NOT (`news_date_unpublish` IS NOT NULL AND `news_date_unpublish` <= CURRENT_TIMESTAMP())) GROUP BY `Ym` ORDER BY `Y` DESC, `m` ASC "; $result = mysql_query($query) or die((DEBUG ? sprintf('

%s

%s

%s
', _('Ett fel uppstod'), mysql_error(), str_replace("\t", "", $query)) : _('Ett fel uppstod, kontakta supporten.'))); if(mysql_num_rows($result) !== 0){ while($res = mysql return $Data; } /* group_props -- ---------------*/ public static function SetProp($UserId, $Prop, $Value = null){ if((int)$UserId === 0) return false; $dbh = Database::getInstance(); $Props = self::GetProps($UserId); if(isset($Props[$Prop]) && is_null($Value)){ unset($Props[$Prop]); }elseif(!is_null($Value)){ $Props[$Prop] = $Value; } $pst = null; return self::SaveProps($UserId, $Props); } public static function GetProps($UserId){ if((int)$UserId === 0) return false; $dbh = Database::getInstance(); $query = " SELECT `user_data` FROM `school_user` WHERE `user_id` = :UserId "; $pst = $dbh->prepare($query); $pst->bindParam(":UserId", $UserId, PDO::PARAM_INT); $pst->execute(); if($pst->rowCount() === 0) return []; $res = $pst->fetch(PDO::FETCH_ASSOC); if(false === $Props = @unserialize($res['user_data'])) return []; return $Props; } public static function SaveProps($UserId, $Props){ if((int)$UserId === 0) return false; $dbh = Database::getInstance(); $P = null; if(is_array($Props) && count($Props) !== 0) $P = @serialize($Props); $query = " UPDATE `school_user` SET `user_data` = :Props WHERE `user_id` = :UserId "; $pst = $dbh->prepare($query); $pst->bindParam(":UserId", $UserId, PDO::PARAM_INT); $pst->bindParam(":Props", $P, PDO::PARAM_STR); $pst->execute(); return ($pst->rowCount() === 1); } function __destruct(){ $this->dbh = null; } } if(!class_exists('UserException')){ Class UserException extends Exception { } }