From 3eb331a487dd6e65da4d6906e75f704ff55b8594 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 25 Sep 2014 09:53:13 +0200 Subject: [PATCH] only copy config if not exists --- asd_news/.gitignore | 2 + asd_news/README.md | 59 + asd_news/classes/rex_asd_news.php | 484 ++++ asd_news/classes/rex_asd_news_utils.php | 40 + asd_news/classes/rex_asd_pager.php | 57 + asd_news/classes/rex_news_form.php | 48 + asd_news/config.inc.php | 163 ++ asd_news/data/config.json | 5 + asd_news/files/help_url_control_settings.png | Bin 0 -> 94886 bytes .../ui-bg_diagonals-small_40_db4865_40x40.png | Bin 0 -> 332 bytes .../ui-bg_diagonals-small_50_93c3cd_40x40.png | Bin 0 -> 333 bytes .../ui-bg_diagonals-small_50_ff3853_40x40.png | Bin 0 -> 330 bytes .../ui-bg_diagonals-small_75_ccd232_40x40.png | Bin 0 -> 333 bytes .../ui-bg_dots-medium_80_ffff38_4x4.png | Bin 0 -> 225 bytes .../images/ui-bg_dots-small_35_35414f_2x2.png | Bin 0 -> 223 bytes .../images/ui-bg_flat_75_ba9217_40x100.png | Bin 0 -> 206 bytes .../images/ui-bg_flat_75_ffffff_40x100.png | Bin 0 -> 208 bytes .../ui-bg_white-lines_85_f7f7ba_40x100.png | Bin 0 -> 364 bytes .../files/images/ui-icons_454545_256x240.png | Bin 0 -> 6992 bytes .../files/images/ui-icons_88a206_256x240.png | Bin 0 -> 4549 bytes .../files/images/ui-icons_c02669_256x240.png | Bin 0 -> 4549 bytes .../files/images/ui-icons_e1e463_256x240.png | Bin 0 -> 4549 bytes .../files/images/ui-icons_ffeb33_256x240.png | Bin 0 -> 4549 bytes .../files/images/ui-icons_ffffff_256x240.png | Bin 0 -> 6299 bytes asd_news/files/jquery-ui-timepicker.js | 2237 +++++++++++++++++ asd_news/files/jquery-ui.min.css | 9 + asd_news/files/jquery-ui.min.js | 7 + asd_news/files/news.css | 37 + asd_news/files/unpublished.svg | 1 + asd_news/functions/asd_news_jquery.php | 18 + asd_news/functions/rex_asd_news_language.php | 116 + asd_news/install.inc.php | 55 + asd_news/lang/de_de.lang | 32 + asd_news/lang/en_gb.lang | 32 + asd_news/modules/modulAusgabe.php | 73 + asd_news/modules/modulEingabe.php | 2 + asd_news/pages/faq.php | 15 + asd_news/pages/index.inc.php | 34 + asd_news/pages/metainfo.php | 5 + asd_news/pages/news.php | 256 ++ asd_news/pages/rubric.php | 63 + asd_news/pages/settings.php | 177 ++ asd_news/uninstall.inc.php | 7 + asd_news/update.inc.php | 12 + install.inc.php | 10 +- update.inc.php | 11 +- 46 files changed, 4059 insertions(+), 8 deletions(-) create mode 100644 asd_news/.gitignore create mode 100644 asd_news/README.md create mode 100644 asd_news/classes/rex_asd_news.php create mode 100644 asd_news/classes/rex_asd_news_utils.php create mode 100644 asd_news/classes/rex_asd_pager.php create mode 100644 asd_news/classes/rex_news_form.php create mode 100644 asd_news/config.inc.php create mode 100644 asd_news/data/config.json create mode 100644 asd_news/files/help_url_control_settings.png create mode 100644 asd_news/files/images/ui-bg_diagonals-small_40_db4865_40x40.png create mode 100644 asd_news/files/images/ui-bg_diagonals-small_50_93c3cd_40x40.png create mode 100644 asd_news/files/images/ui-bg_diagonals-small_50_ff3853_40x40.png create mode 100644 asd_news/files/images/ui-bg_diagonals-small_75_ccd232_40x40.png create mode 100644 asd_news/files/images/ui-bg_dots-medium_80_ffff38_4x4.png create mode 100644 asd_news/files/images/ui-bg_dots-small_35_35414f_2x2.png create mode 100644 asd_news/files/images/ui-bg_flat_75_ba9217_40x100.png create mode 100644 asd_news/files/images/ui-bg_flat_75_ffffff_40x100.png create mode 100644 asd_news/files/images/ui-bg_white-lines_85_f7f7ba_40x100.png create mode 100644 asd_news/files/images/ui-icons_454545_256x240.png create mode 100644 asd_news/files/images/ui-icons_88a206_256x240.png create mode 100644 asd_news/files/images/ui-icons_c02669_256x240.png create mode 100644 asd_news/files/images/ui-icons_e1e463_256x240.png create mode 100644 asd_news/files/images/ui-icons_ffeb33_256x240.png create mode 100644 asd_news/files/images/ui-icons_ffffff_256x240.png create mode 100644 asd_news/files/jquery-ui-timepicker.js create mode 100644 asd_news/files/jquery-ui.min.css create mode 100644 asd_news/files/jquery-ui.min.js create mode 100644 asd_news/files/news.css create mode 100644 asd_news/files/unpublished.svg create mode 100644 asd_news/functions/asd_news_jquery.php create mode 100644 asd_news/functions/rex_asd_news_language.php create mode 100644 asd_news/install.inc.php create mode 100644 asd_news/lang/de_de.lang create mode 100644 asd_news/lang/en_gb.lang create mode 100644 asd_news/modules/modulAusgabe.php create mode 100644 asd_news/modules/modulEingabe.php create mode 100644 asd_news/pages/faq.php create mode 100644 asd_news/pages/index.inc.php create mode 100644 asd_news/pages/metainfo.php create mode 100644 asd_news/pages/news.php create mode 100644 asd_news/pages/rubric.php create mode 100644 asd_news/pages/settings.php create mode 100644 asd_news/uninstall.inc.php create mode 100644 asd_news/update.inc.php diff --git a/asd_news/.gitignore b/asd_news/.gitignore new file mode 100644 index 0000000..af52505 --- /dev/null +++ b/asd_news/.gitignore @@ -0,0 +1,2 @@ +.idea/* +dummy.php \ No newline at end of file diff --git a/asd_news/README.md b/asd_news/README.md new file mode 100644 index 0000000..33f7d98 --- /dev/null +++ b/asd_news/README.md @@ -0,0 +1,59 @@ +ASD News AddOn für REDAXO 4.6+ +============================== + +Features +-------- + +* Kompatibel mit SEO AddOns "seo42", "yrewrite", "rexseo" +* Kompatibel mit Plugin "url_control" +* Mehrsprachigkeit +* Erweiterung von Meta-Tags möglich (siehe `rex_asd_news::replaceSeoTags()`) +* SEO42 Image Manager Urls möglich +* On/Off Schaltung von News + +Update 1.1.0 +------------ +* Methode `$news->isOnline()` hinzugefügt +* Neuste News zuerst +* Config in Data Ordner für Updatefähigkeit +* Veröffentlichen Bugfix unter Windows +* Rubrik Editieren Bugfix +* url_generate::generatePathFile beim hinzfügen/editieren einer News +* Where Condition flexibler gestaltet +* Erfolgsmeldung beim speichern der Einstellungen + + +PHP Methoden +------------ + +* Einzelne News +```$news = rex_asd_news::getNewsById((int)$id);``` + +* Mehrere News +```$news = rex_asd_news::getNewsByIds(array(1, 2, 3, 4));``` + +* Mehrere News von einer Kategorie +```$news = rex_asd_news::getNewsByCategory((int)$catId);``` + +* News ID bekommen +```$newsId = rex_asd_news::getNewsId();``` + +* SQL Spalte bekommen (siehe `rex_sql::getValue`) +```$title = $news->getValue('title', $default = null);``` + +* URL bekommen +```$url = $news->getUrl($params = array());``` + +* PublishDate bekommen als DateTime Objekt* +```$date = $news->getPublishDate();``` + +* Monatname bekommen +```$monthName = $news->getMonthName($lang = '_de');``` + +* Meta Tags einfügen +``` +$news->replaceSeoTags(array( + 'keywords' => $foo, + 'og:image' => $news->getImage() +)); +``` \ No newline at end of file diff --git a/asd_news/classes/rex_asd_news.php b/asd_news/classes/rex_asd_news.php new file mode 100644 index 0000000..9ec82d9 --- /dev/null +++ b/asd_news/classes/rex_asd_news.php @@ -0,0 +1,484 @@ + 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', + 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' + ); + + public static $month_en = array( + 1 => 'Januar', 'Februar', 'March', 'April', 'Mai', 'June', + 'July', 'August', 'September', 'October', 'November', 'December' + ); + + /** + * initial the class + * @param mixed $arg1 a sql Object, or int + * @param int $arg2 + */ + public function __construct($arg1, $arg2 = null) + { + // SQL Object + if (is_object($arg1) && is_null($arg2)) { + + $this->setSql($arg1); + + } else { + + $this->setVars($arg1, $arg2); + + } + + } + + /** + * set the sql object + * @param rex_sql $sql SQL-object + * @return self + */ + public function setSql(rex_sql $sql) + { + $this->sql = $sql; + + return $this; + } + + /** + * set id and clang for a sql-query + * @param int $id + * @param int $clang + * @return self + */ + public function setVars($id, $clang = null) + { + global $REX; + + if ($clang == null) { + $clang = $REX['CUR_CLANG']; + } + + $this->setSql(new rex_sql); + $this->sql->setQuery('SELECT * FROM `' . $REX['TABLE_PREFIX'] . 'asd_news` WHERE `id` = ' . (int)$id . ' AND `clang` = ' . (int)$clang); + + return $this; + } + + /** + * @see rex_sql::getValue + * @return mixed + */ + public function getValue($name, $default = null) + { + return $this->sql->getValue($name, $default); + } + + /** + * @return DateTime + */ + public function getPublishDate() + { + return new DateTime($this->getValue('publishedAt')); + } + + /** + * get the Month as word + * + * @param string $lang + * @return string + */ + public function getMonthName($lang = 'de') + { + $date = $this->getPublishDate(); + $varName = 'month_' . $lang; + + $name = self::$$varName; + + return $name[$date->format('n')]; + } + + /** + * get the Image Path + * @param string|null $imageType imagemanager-type + * @return string + */ + public function getImage($imageType = null) + { + + $default = '/files/' . $this->getValue('picture'); + $defaultType = 'index.php?rex_img_type=' . $imageType . '&rex_img_file=' . $this->getValue('picture'); + + if (self::$SEO_ADDON == 'seo42') { + + if ($imageType != null) { + return seo42::getImageManagerFile($this->getValue('picture'), $imageType); + } + + return seo42::getMediaFile($this->getValue('picture')); + + } + + /* + if (self::$SEO_ADDON == 'yrewrite') { + + if ($imageType != null) { + return $defaultType; + } + + return $default; + + } + + if (self::$SEO_ADDON == 'rexseo') { + + if ($imageType != null) { + return $defaultType; + } + + return $default; + + } + */ + + if ($imageType != null) { + return $defaultType; + } + + return $default; + } + + /** + * return the news Url + * @param array $params add Params for the Url + * @return string + */ + public function getUrl(array $params = array()) + { + global $REX; + + $params = array_merge(array('news-id' => $this->getValue('id')), $params); + + if (self::$SEO_URL_CONTROL) { + return url_generate::getUrlById($REX['TABLE_PREFIX'] . 'asd_news', $this->getValue('id')); + } + + return rex_getUrl($REX['ARTICLE_ID'], $REX['CUR_CLANG'], $params); + } + + /** + * is the news online? + * + * @return bool + */ + public function isOnline() + { + return ($this->getValue('online') == 1); + } + + /** + * set the SEO Params (keywords, description, ...) + * at the moment use self::replaceSeoTags() + * + * @return self + */ + public function setSEOParams() + { + return $this; + } + + /** + * replace the meta keywords, description html tags + * + * replaceSeoTags(array( + * 'keywords' => $news->getValue('keywords') + * 'description' => $news->getValue('description') + * 'og:description' => $news->getValue('facebook_description') + * )); + * + * @param array $tagNames + * @return self + */ + public function replaceSeoTags(array $tagNames) + { + $self = $this; + + $tagNames = rex_register_extension_point('ASD_NEWS_SEOTAGS', $tagNames); + + rex_register_extension('OUTPUT_FILTER', function ($subject) use ($tagNames, $self) { + + try { + + $document = new DOMDocument(); + $document->formatOutput = true; + @$document->loadHTML($subject['subject']); + $metaList = $document->getElementsByTagName('meta'); + + + foreach ($metaList as $meta) { + /** @var DOMElement $meta */ + + if (!isset($tagNames[$meta->getAttribute('name')])) { + + if (!isset($tagNames[$meta->getAttribute('property')])) { + + continue; + + } else { + + $tagName = $tagNames[$meta->getAttribute('property')]; + + } + + } else { + $tagName = $tagNames[$meta->getAttribute('name')]; + } + + $meta->setAttribute('content', $tagName); + + unset($tagNames[$meta->getAttribute('name')]); + } + + if (count($tagNames)) { + + $metaLast = $metaList->item($metaList->length - 1); + + foreach ($tagNames as $name => $content) { + + $attribute = (substr($name, 0, 3) == 'og:') ? 'property' : 'name'; + + $element = $document->createElement('meta'); + $element->setAttribute($attribute, $name); + $element->setAttribute('content', $content); + + $metaLast->parentNode->insertBefore($element, $metaLast->nextSibling); + + } + + } + + } catch (DOMException $e) { + echo rex_warning($e->getMessage()); + } + + return $document->saveHTML(); + + }); + + return $this; + } + + /** + * get the news ID for the Frontend + * @return int|null + */ + public static function getNewsId() + { + global $REX; + + $id = null; + + if (self::$SEO_URL_CONTROL) { + $id = url_generate::getId($REX['TABLE_PREFIX'] . 'asd_news'); + } + + if ($id == null) { + $id = (int)rex_request('news-id'); + } + + return $id; + } + + /** + * return an array of news filtered by the category + * + * @param int $cat + * @param int|null $clang + * @return array + */ + public static function getNewsByCategory($cat, $clang = null) + { + return self::getByWhere(array( + 'category' => '= ' . (int)$cat + ), $clang); + } + + /** + * return an array of news filtered by Ids + * + * @param array $newsIds + * @param int|null $clang + * @return array + */ + public static function getNewsByIds($newsIds, $clang = null) + { + return self::getByWhere(array( + 'id' => 'IN (' . implode(',', (array)$newsIds) . ')' + ), $clang); + } + + /** + * return an news filtered by id + * + * @param int $newsId + * @param int|null $clang + * @return array + */ + public static function getNewsById($newsId, $clang = null) + { + $news = self::getByWhere(array( + 'id' => '= ' . (int)$newsId + ), $clang); + + return $news[0]; + } + + /** + * @return array + */ + public static function getAllNews($clang = null) + { + return self::getByWhere(array( + '1' => '= 1' + ), $clang); + } + + /** + * @param DateTime $date + * @param null|DateTime $date2 + * @param int|null $clang + * @return array + */ + public static function getNewsByPublishDate(DateTime $date, $date2 = null, $clang = null) + { + if ($date2 == null) { + return self::getByWhere(array( + 'publishedAt' => '<= "' . $date->format('Y-m-d H:i:s') . '"' + ), $clang); + } + + return self::getByWhere(array( + 'publishedAt' => 'BETWEEN "' . $date->format('Y-m-d H:i:s') . '" + AND "' . $date2->format('Y-m-d H:i:s') . '"' + ), $clang); + } + + /** + * return an array of news filtered by a Where + * + * @param string $where + * @param int|null $clang + * @return array + */ + private static function getByWhere($where, $clang = null) + { + global $REX; + + if ($clang == null) { + $clang = $REX['CUR_CLANG']; + } + + $where = array_merge(self::getDefaultWhere($clang), $where); + + $where = self::generateWhere($where); + + $news = array(); + + $sql = new rex_sql(); + $sql->setQuery(' + SELECT * + FROM `' . $REX['TABLE_PREFIX'] . 'asd_news` + ' . $where . ' + ORDER BY `publishedAt` DESC'); + + for ($i = 1; $i <= $sql->getRows(); $i++) { + + $news[] = new self(clone $sql); + + $sql->next(); + } + + return $news; + } + + /** + * @param int $clang + * @return array + */ + private function getDefaultWhere($clang) + { + return array( + 'clang' => '= ' . $clang, + 'publishedAt' => 'BETWEEN "0000-00-00 00:01:00" AND "' . date('Y-m-d H:i:s') . '"' + ); + } + + /** + * @param array $whereArray + * @return string + */ + private function generateWhere(array $whereArray) + { + $where = array(); + foreach ($whereArray as $name => $condition) { + $where[] = '`' . $name . '` ' . $condition; + } + + return 'WHERE ' . implode(' AND ' . PHP_EOL, $where); + } + + /** + * return a select HTML-Tag + * + * @param string $name + * @param string $value + * @return string + */ + public static function getCategorySelect($name, $value) + { + global $REX; + + $return = '').find("select"); + $.fn.append.apply(this.timezone_select, + $.map(o.timezoneList, function (val, idx) { + return $("