Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: dev-branches/tic6013-opengraph/db/migrations/174_change_opengraph_data_pk.php
- ===================================================================
- --- dev-branches/tic6013-opengraph/db/migrations/174_change_opengraph_data_pk.php (revision 35422)
- +++ dev-branches/tic6013-opengraph/db/migrations/174_change_opengraph_data_pk.php (revision 35422)
- @@ -0,0 +1,33 @@
- +<?php
- +/**
- + * Add a numeric id column to table "opengraphdata" in order to avoid problems
- + * with innodb and to reduce key size.
- + *
- + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
- + * @license GPL2 or any later version
- + */
- +class ChangeOpengraphDataPk extends Migration
- +{
- + public function up()
- + {
- + $query = "ALTER TABLE `opengraphdata`
- + DROP PRIMARY KEY,
- + ADD COLUMN `opengraph_id` INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST,
- + ADD UNIQUE KEY `url` (`url`(512))";
- + DBManager::get()->exec($query);
- +
- + SimpleORMap::expireTableScheme();
- + }
- +
- + public function down()
- + {
- + $query = "ALTER TABLE `opengraphdata`
- + DROP PRIMARY KEY,
- + DROP INDEX `url`,
- + DROP COLUMN `opengraph_id`,
- + ADD PRIMARY KEY (`url`)";
- + DBManager::get()->exec($query);
- +
- + SimpleORMap::expireTableScheme();
- + }
- +}
- Index: dev-branches/tic6013-opengraph/lib/classes/FormattedContent.php
- ===================================================================
- --- dev-branches/tic6013-opengraph/lib/classes/FormattedContent.php (revision 35422)
- +++ dev-branches/tic6013-opengraph/lib/classes/FormattedContent.php (revision 35422)
- @@ -0,0 +1,71 @@
- +<?php
- +use Studip\Markup;
- +
- +/**
- + * Storage for formatted content
- + *
- + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
- + * @license GPL2 or any later version
- + * @since Stud.IP 3.4
- + */
- +class FormattedContent
- +{
- + protected $format;
- + protected $formatted_content = null;
- +
- + /**
- + * Constructs the object for the given content (with the given format).
- + * If no format is provided, the default StudipFormat will be used.
- + *
- + * @param String $content Content to format
- + * @param mixed $format Used format (optional, defaults to StudipFormat)
- + */
- + public function __construct($content, StudipFormat $format = null)
- + {
- + $this->format = $format ?: new StudipFormat;
- +
- + $formatted = Markup::apply($this->format, $content, false);
- + $wrapped = sprintf(FORMATTED_CONTENT_WRAPPER, $formatted);
- +
- + $this->formatted_content = $wrapped;
- + }
- +
- + /**
- + * Returns the formatted content (optionally with the opengraph data
- + * included).
- + *
- + * @param bool $include_open_graph Append the rendered opengraph data
- + * (optional, defaults to false)
- + * @return String containg the formatted content as html
- + */
- + public function getContent($include_open_graph = false)
- + {
- + $result = $this->formatted_content;
- + if ($include_open_graph) {
- + $result .= $this->getOpenGraphURLCollection()->render();
- + }
- + return $result;
- + }
- +
- + /**
- + * Return the detected opengraph urls as a collection.
- + *
- + * @return OpenGraphURLCollection Collected opengraph urls
- + */
- + public function getOpenGraphURLCollection()
- + {
- + return $this->format->getOpenGraphCollection();
- + }
- +
- + /**
- + * Converts the object to a string by returning the formatted content.
- + * This will be used a lot since formatReady() is usually expected to
- + * return a string.
- + *
- + * @return String containing the formatted content as html
- + */
- + public function __toString()
- + {
- + return $this->getContent();
- + }
- +}
- Index: dev-branches/tic6013-opengraph/lib/classes/StudipFormat.php
- ===================================================================
- --- trunk/lib/classes/StudipFormat.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/lib/classes/StudipFormat.php (revision 35422)
- @@ -292,4 +292,6 @@
- }
- + private $opengraph_collection;
- +
- /**
- * Initializes a new StudipFormat instance.
- @@ -298,4 +300,33 @@
- {
- parent::__construct(self::getStudipMarkups());
- +
- + // StudipFormat::markupLinks stores OpenGraph media preview URLs
- + // Blubber and Forum plugins add media previews after formatReady
- + // returns
- + $this->opengraph_collection = new OpenGraphURLCollection();
- + }
- +
- + /**
- + * Add an url to the opengraph collection. The url will only be added
- + * if it exists does not yet exists in the collection.
- + *
- + * @param String $url URL to add.
- + */
- + public function addOpenGraphURL($url)
- + {
- + $og = OpenGraphURL::fromURL($url);
- + if ($og && !$this->opengraph_collection->find($og->id)) {
- + $this->opengraph_collection[] = $og;
- + }
- + }
- +
- + /**
- + * Returns the collected opengraph urls.
- + *
- + * @return OpenGraphURLCollection Collection of opengraph urls
- + */
- + public function getOpenGraphCollection()
- + {
- + return $this->opengraph_collection;
- }
- @@ -626,16 +657,14 @@
- protected static function markupLinks($markup, $matches)
- {
- - if ($markup->isInsideOf('htmlAnchor')
- - || $markup->isInsideOf('htmlImg')
- - ) {
- + if ($markup->isInsideOf('htmlAnchor') || $markup->isInsideOf('htmlImg')) {
- return $matches[0];
- }
- - $url = $matches[2];
- - $title = $matches[1] ? $matches[1] : $url;
- + $url = $matches[2];
- + $title = $matches[1] ?: $url;
- $intern = isLinkIntern($url);
- - if (!$intern) {
- - OpenGraphURL::$tempURLStorage[] = $url;
- + if (!$intern && Config::get()->OPENGRAPH_ENABLE && method_exists($markup, 'addOpenGraphURL')) {
- + $markup->addOpenGraphURL($url);
- }
- @@ -643,11 +672,11 @@
- $linkmarkup = clone $markup;
- - $linkmarkup->removeMarkup("links");
- - $linkmarkup->removeMarkup("wiki-links");
- + $linkmarkup->removeMarkup('links');
- + $linkmarkup->removeMarkup('wiki-links');
- return sprintf('<a class="%s" href="%s"%s>%s</a>',
- - $intern ? "link-intern" : "link-extern",
- + $intern ? 'link-intern' : 'link-extern',
- $url,
- - $intern ? "" : ' target="_blank"',
- + $intern ? '' : ' target="_blank"',
- $linkmarkup->format($title)
- );
- Index: dev-branches/tic6013-opengraph/lib/classes/StudipTransformFormat.php
- ===================================================================
- --- trunk/lib/classes/StudipTransformFormat.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/lib/classes/StudipTransformFormat.php (revision 35422)
- @@ -111,12 +111,6 @@
- $url = $matches[2];
- $intern = isLinkIntern($url);
- - $ogurl = new OpenGraphURL($url);
- - if (!$intern && ($ogurl->isNew() || $ogurl['last_update'] < time() - 86400)) {
- - $ogurl->fetch();
- - $ogurl['last_update'] = time();
- - $ogurl->store();
- - } elseif(!$ogurl->isNew()) {
- - $ogurl['chdate'] = time();
- - $ogurl->store();
- + if (!$intern) {
- + OpenGraphURL::fromURL($url)->store();
- }
- return $matches[0];
- Index: dev-branches/tic6013-opengraph/lib/models/OpenGraphURL.class.php
- ===================================================================
- --- trunk/lib/models/OpenGraphURL.class.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/lib/models/OpenGraphURL.class.php (revision 35422)
- @@ -25,8 +25,13 @@
- * @property string mkdate database column
- */
- -class OpenGraphURL extends SimpleORMap {
- -
- - static public $tempURLStorage = array(); //place to store opengraph-urls from a text.
- -
- +class OpenGraphURL extends SimpleORMap
- +{
- + const EXPIRES_DURATION = 86400; // = 24 * 60 * 60
- +
- + /**
- + * Configures this model.
- + *
- + * @param Array $config Configuration array
- + */
- protected static function configure($config = array())
- {
- @@ -35,4 +40,62 @@
- $config['default_values']['data'] = '';
- parent::configure($config);
- + }
- +
- + /**
- + * Create an instance of this model given url. Differs from findOneByURL
- + * insofar that it will return a new object with the given url set
- + * instead of null.
- + *
- + * @param String $url URL to find
- + * @return OpenGraphURL Either existing instance or a new instance for
- + * the given url
- + */
- + public static function fromURL($url)
- + {
- + $og = self::findOneByUrl($url);
- + if (!$og) {
- + $og = new self();
- + $og->url = $url;
- + }
- + return $og;
- + }
- +
- + /**
- + * Constructor of the object. Provides a fallback if a url is passed
- + * instead of the usually expected numeric id in order to not break
- + * backward compatibility.
- + * But this constructor will fail miserably if a url is passed that
- + * is not in the database. This was chosen by design to encourage the
- + * correct use of an id.
- + *
- + * @param mixed $id Numeric id, existing url or null
- + */
- + public function __construct($id = null)
- + {
- + // Try to find matching id when an url is passed instead of an id.
- + // This is to ensure that no legacy code will immediately break.
- + if ($id !== null && !ctype_digit($id)) {
- + $temp = self::findOneByUrl($id);
- + if ($temp) {
- + $id = $temp->id;
- + }
- + }
- + parent::__construct($id);
- + }
- +
- + /**
- + * Stores the object and fetches the opengraph information when either
- + * the object is new or outdated.
- + *
- + * @return int Number of updated records
- + */
- + public function store()
- + {
- + if ($this->isNew() || $this->last_update < time() - self::EXPIRES_DURATION) {
- + $this->fetch();
- + $this->last_update = time();
- + }
- +
- + return parent::store();
- }
- @@ -44,6 +107,7 @@
- * indicates that the site is no opengraph node at all.
- */
- - public function fetch() {
- - if (!get_config("OPENGRAPH_ENABLE")) {
- + public function fetch()
- + {
- + if (!get_config('OPENGRAPH_ENABLE')) {
- return;
- }
- @@ -53,5 +117,5 @@
- $currentEncoding = $match[0];
- } else {
- - $currentEncoding = "ISO-8859-1";
- + $currentEncoding = 'ISO-8859-1';
- }
- @@ -77,11 +141,12 @@
- foreach ($metatags as $tag) {
- $key = false;
- - if ($tag->hasAttribute('property') &&
- - strpos($tag->getAttribute('property'), 'og:') === 0) {
- + if ($tag->hasAttribute('property')
- + && strpos($tag->getAttribute('property'), 'og:') === 0)
- + {
- $key = strtolower(substr($tag->getAttribute('property'), 3));
- }
- - if (!$key &&
- - $tag->hasAttribute('name') &&
- - strpos($tag->getAttribute('name'), 'og:') === 0) {
- + if (!$key && $tag->hasAttribute('name')
- + && strpos($tag->getAttribute('name'), 'og:') === 0)
- + {
- $key = strtolower(substr($tag->getAttribute('name'), 3));
- }
- @@ -107,5 +172,6 @@
- foreach ($metatags as $tag) {
- if (stripos($tag->getAttribute('name'), "description") !== false
- - || stripos($tag->getAttribute('property'), "description") !== false) {
- + || stripos($tag->getAttribute('property'), "description") !== false)
- + {
- $this['description'] = studip_utf8decode($tag->getAttribute('content'));
- }
- @@ -120,12 +186,14 @@
- * Renders a small box with the information of the opengraph url. Used in
- * blubber and in the forum.
- - * @return string : html output of the box.
- - */
- - public function render() {
- - if (!get_config("OPENGRAPH_ENABLE") || !$this->getValue('is_opengraph')) {
- - return "";
- - }
- - $template = $GLOBALS['template_factory']->open("shared/opengraphinfo_wide.php");
- - $template->set_attribute('og', $this);
- + *
- + * @return string html output of the box.
- + */
- + public function render()
- + {
- + if (!get_config('OPENGRAPH_ENABLE') || !$this->getValue('is_opengraph')) {
- + return '';
- + }
- + $template = $GLOBALS['template_factory']->open('shared/opengraphinfo_wide.php');
- + $template->og = $this;
- return $template->render();
- }
- @@ -135,8 +203,10 @@
- * Each array-entry is an array itself with the url as first parameter and the
- * content-type (important for <audio/> tags) as the second.
- + *
- * @return array(array($url, $content_type), ...)
- */
- - public function getAudioFiles() {
- - return $this->getMediaFiles("audio");
- + public function getAudioFiles()
- + {
- + return $this->getMediaFiles('audio');
- }
- @@ -145,8 +215,10 @@
- * Each array-entry is an array itself with the url as first parameter and the
- * content-type (important for <video/> tags) as the second.
- + *
- * @return array(array($url, $content_type), ...)
- */
- - public function getVideoFiles() {
- - return $this->getMediaFiles("video");
- + public function getVideoFiles()
- + {
- + return $this->getMediaFiles('video');
- }
- @@ -155,8 +227,10 @@
- * Each array-entry is an array itself with the url as first parameter and the
- * content-type (important for <audio/> or <video/> tags) as the second.
- - * @param string $type: "audio" or "video"
- + *
- + * @param string $type "audio" or "video"
- * @return array(array($url, $content_type), ...)
- */
- - protected function getMediaFiles($type) {
- + protected function getMediaFiles($type)
- + {
- $files = array();
- $media = array();
- Index: dev-branches/tic6013-opengraph/lib/models/OpenGraphURLCollection.class.php
- ===================================================================
- --- dev-branches/tic6013-opengraph/lib/models/OpenGraphURLCollection.class.php (revision 35422)
- +++ dev-branches/tic6013-opengraph/lib/models/OpenGraphURLCollection.class.php (revision 35422)
- @@ -0,0 +1,53 @@
- +<?php
- +/**
- + * Specialized version of SimpleORMapCollection that accepts only
- + * OpenGraphURL objects and provides a method that renders the collection
- + * to html.
- + *
- + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
- + * @license GPL2 or any later version
- + */
- +class OpenGraphURLCollection extends SimpleORMapCollection
- +{
- + /**
- + * Returns the class name of the object this collection accepts.
- + *
- + * @return String containing the provided class name 'OpenGraphURL'
- + */
- + public function getClassName()
- + {
- + return 'OpenGraphURL';
- + }
- +
- + /**
- + * Renders the collection to html. The collection is usually wrapped in
- + * a wrapper element but in some edge cases you might want to choose not
- + * to do so. This is enabled by the only parameter this method accepts.
- + *
- + * Note: I advice you not to exclude the wrapper. The javascript that
- + * handles the collection will fail!
- + *
- + * @param bool $with_wrapper Should the collection be wrapped in a wrapper
- + * element (optional, defaults to true)
- + * @return String containing the rendered collection as a html chunk
- + */
- + public function render($with_wrapper = true)
- + {
- + if (!Config::Get()->OPENGRAPH_ENABLE || count($this) === 0) {
- + return '';
- + }
- +
- + $rendered_urls = $this->sendMessage('render');
- + $rendered_urls = array_filter($rendered_urls);
- +
- + if ($with_wrapper) {
- + $template = $GLOBALS['template_factory']->open('shared/opengraph-container.php');
- + $template->urls = $rendered_urls;
- + $result = $template->render();
- + } else {
- + $result = implode("\n", $rendered_urls);
- + }
- +
- + return $result;
- + }
- +}
- Index: dev-branches/tic6013-opengraph/lib/visual.inc.php
- ===================================================================
- --- trunk/lib/visual.inc.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/lib/visual.inc.php (revision 35422)
- @@ -267,14 +267,16 @@
- * @param boolean $wiki (deprecated, has no effect)
- * @param string $show_comments (deprecated, has no effect)
- - * @return string HTML code computed by applying markup-rules.
- + * @return FormattedContent Object containing the HTML code computed by
- + * applying markup-rules (will convert itself to
- + * string if neccessary).
- */
- // TODO remove unused function arguments
- -function formatReady($text, $trim=TRUE, $extern=FALSE, $wiki=FALSE, $show_comments='icon'){
- - // StudipFormat::markupLinks stores OpenGraph media preview URLs
- - // Blubber and Forum plugins add media previews after formatReady returns
- - OpenGraphURL::$tempURLStorage = array();
- -
- - return sprintf(FORMATTED_CONTENT_WRAPPER,
- - Markup::apply(new StudipFormat(), $text, $trim));
- +function formatReady($text, $trim=TRUE, $extern=FALSE, $wiki=FALSE, $show_comments='icon')
- +{
- + if ($trim) {
- + $text = trim($text);
- + }
- +
- + return new FormattedContent($text);
- }
- Index: dev-branches/tic6013-opengraph/public/assets/javascripts/application.js
- ===================================================================
- --- trunk/public/assets/javascripts/application.js (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/assets/javascripts/application.js (revision 35422)
- @@ -394,2 +394,44 @@
- }
- })(window.print);
- +
- +// OpenGraph
- +$(document).on('dialog-update ready ajaxComplete', function () {
- + $('.opengraph-area:not(.handled)').each(function () {
- + var items = $('.opengraph', this),
- + switcher;
- + if (items.length > 1) {
- + items.filter(':gt(0)').addClass('hidden');
- +
- + switcher = $('<ul class="switcher">');
- + $('<li><button class="switch-left" disabled><</button></li>').appendTo(switcher);
- + $('<li><button class="switch-right">></button></li>').appendTo(switcher);
- + switcher.prependTo(this);
- + }
- +
- + $(this).addClass('handled');
- + });
- +}).on('click', '.opengraph-area .switcher button', function (event) {
- + var direction = $(this).is('.switch-left') ? 'left' : 'right',
- + current = $(this).closest('.opengraph-area').find('.opengraph:visible'),
- + switcher = $(this).closest('.switcher'),
- + buttons = {left: $('.switch-left', switcher),
- + right: $('.switch-right', switcher)};
- +
- + if (direction === 'left') {
- + current = current.addClass('hidden').prev().removeClass('hidden');
- + buttons.left.attr('disabled', current.prev('.opengraph').length === 0);
- + buttons.right.attr('disabled', false);
- + } else {
- + current = current.addClass('hidden').next().removeClass('hidden');
- + buttons.left.attr('disabled', false);
- + buttons.right.attr('disabled', current.next('.opengraph').length === 0);
- + }
- +
- + event.preventDefault();
- +}).on('click', '.opengraph a.flash-embedder', function (event) {
- + var url = $(this).attr('href'),
- + template = _.template('<iframe width="100%" height="200px" frameborder="0" src="<%= url %>"></iframe>');
- + $(this).replaceWith(template({url: url}));
- +
- + event.preventDefault();
- +});
- Index: dev-branches/tic6013-opengraph/public/assets/stylesheets/less/opengraph.less
- ===================================================================
- --- trunk/public/assets/stylesheets/less/opengraph.less (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/assets/stylesheets/less/opengraph.less (revision 35422)
- @@ -1,17 +1,70 @@
- -.opengraph {
- - font-size: 0.8em;
- - border: thin solid lightgrey;
- - padding: 10px;
- - margin-top: 10px;
- - min-height: 120px;
- -
- - margin-left: auto;
- - margin-right: auto;
- +.opengraph-area {
- + margin: 10px auto 5px;
- max-width: 700px;
- + .switcher {
- + list-style: none;
- + text-align: right;
- +
- + li {
- + border-top: thin solid @dark-gray-color-20;
- + display: inline-block;
- + padding: 5px;
- +
- + &:first-child {
- + border-left: thin solid @dark-gray-color-20;
- + }
- + &:last-child {
- + border-right: thin solid @dark-gray-color-20;
- + }
- + }
- + .switch-left, .switch-right {
- + .hide-text();
- + .square(20px);
- + background-position: center;
- + background-repeat: no-repeat;
- + padding: 0;
- +
- + &:not([disabled]) {
- + cursor: pointer;
- + }
- + }
- + .switch-left {
- + .retina-background-icon('blue/arr_1left.svg');
- + &[disabled] {
- + .retina-background-icon('grey/arr_1left.svg');
- + }
- + }
- + .switch-right {
- + .retina-background-icon('blue/arr_1right.svg');
- + &[disabled] {
- + .retina-background-icon('grey/arr_1right.svg');
- + }
- + }
- + }
- +
- + .js & .opengraph.hidden,
- + .js &:not(.handled) .opengraph:not(:first-of-type) {
- + // The second selector prevents flash of content before everything
- + // is setup
- + display: none;
- + }
- +}
- +
- +.opengraph {
- + @padding: 10px;
- + @height: 120px;
- +
- + .clearfix;
- +
- + font-size: 0.8em;
- + border: 1px solid @dark-gray-color-20;
- + padding: @padding;
- + min-height: @height;
- +
- .flash-embedder {
- - display: flex;
- - justify-content: center;
- - align-items: center;
- + .flex();
- + .flex-justify-content(center);
- + .flex-align-items(center);
- width: 100%;
- height: 100px;
- @@ -20,45 +73,34 @@
- background-size: 100% auto;
- .play {
- - background-color: rgba(0,0,0,0.7);
- - border-radius: 100px;
- + .border-radius(100px);
- + .transition(background-color 300ms);
- + background-color: rgba(0, 0, 0, 0.7);
- padding: 10px;
- - transition: background-color 0.3s;
- }
- &:hover .play {
- - background-color: rgba(0,0,0,1);
- - transition: background-color 0.3s;
- + background-color: rgba(0, 0, 0, 1);
- }
- }
- - .video {
- - .flash-embedder {
- - height: 200px;
- - }
- - }
- - .audio {
- - text-align: center;
- + .video .flash-embedder {
- + height: 200px;
- }
- a.info {
- + .box-sizing(border-box);
- + color: black;
- display: block;
- word-break: normal !important;
- - color: black;
- + &:hover {
- + color: black;
- + }
- }
- - a.info:hover {
- - color: black;
- - }
- - .info_image {
- - transition: margin, padding, width, height;
- - transition-duration: 100ms;
- - float:left;
- - width: 120px;
- - height: 120px;
- - margin: 0px;
- - margin-right: 10px;
- - padding: 0px;
- - background-size: auto 100%;
- - background-position: center center;
- + .image {
- + .square(@height);
- + background-size: contain;
- + background-position: left center;
- background-repeat: no-repeat;
- + display: inline-block;
- + float: left;
- + margin-right: @padding;
- }
- }
- -
- -
- Index: dev-branches/tic6013-opengraph/public/assets/stylesheets/style.css
- ===================================================================
- --- trunk/public/assets/stylesheets/style.css (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/assets/stylesheets/style.css (revision 35422)
- @@ -5717,17 +5717,100 @@
- display: none;
- }
- +.opengraph-area {
- + margin: 10px auto 5px;
- + max-width: 700px;
- +}
- +.opengraph-area .switcher {
- + list-style: none;
- + text-align: right;
- +}
- +.opengraph-area .switcher li {
- + border-top: thin solid #d8dadc;
- + display: inline-block;
- + padding: 5px;
- +}
- +.opengraph-area .switcher li:first-child {
- + border-left: thin solid #d8dadc;
- +}
- +.opengraph-area .switcher li:last-child {
- + border-right: thin solid #d8dadc;
- +}
- +.opengraph-area .switcher .switch-left,
- +.opengraph-area .switcher .switch-right {
- + font: 0/0 a;
- + color: transparent;
- + text-shadow: none;
- + background-color: transparent;
- + border: 0;
- + width: 20px;
- + height: 20px;
- + background-position: center;
- + background-repeat: no-repeat;
- + padding: 0;
- +}
- +.opengraph-area .switcher .switch-left:not([disabled]),
- +.opengraph-area .switcher .switch-right:not([disabled]) {
- + cursor: pointer;
- +}
- +.opengraph-area .switcher .switch-left {
- + background-image: url("../images/icons/blue/arr_1left.svg");
- + -webkit-background-size: 16px 16px;
- + -moz-background-size: 16px 16px;
- + -o-background-size: 16px 16px;
- + background-size: 16px 16px;
- +}
- +.opengraph-area .switcher .switch-left[disabled] {
- + background-image: url("../images/icons/grey/arr_1left.svg");
- + -webkit-background-size: 16px 16px;
- + -moz-background-size: 16px 16px;
- + -o-background-size: 16px 16px;
- + background-size: 16px 16px;
- +}
- +.opengraph-area .switcher .switch-right {
- + background-image: url("../images/icons/blue/arr_1right.svg");
- + -webkit-background-size: 16px 16px;
- + -moz-background-size: 16px 16px;
- + -o-background-size: 16px 16px;
- + background-size: 16px 16px;
- +}
- +.opengraph-area .switcher .switch-right[disabled] {
- + background-image: url("../images/icons/grey/arr_1right.svg");
- + -webkit-background-size: 16px 16px;
- + -moz-background-size: 16px 16px;
- + -o-background-size: 16px 16px;
- + background-size: 16px 16px;
- +}
- +.js .opengraph-area .opengraph.hidden,
- +.js .opengraph-area:not(.handled) .opengraph:not(:first-of-type) {
- + display: none;
- +}
- .opengraph {
- + *zoom: 1;
- font-size: 0.8em;
- - border: thin solid lightgrey;
- + border: 1px solid #d8dadc;
- padding: 10px;
- - margin-top: 10px;
- min-height: 120px;
- - margin-left: auto;
- - margin-right: auto;
- - max-width: 700px;
- +}
- +.opengraph:before,
- +.opengraph:after {
- + display: table;
- + content: "";
- + line-height: 0;
- +}
- +.opengraph:after {
- + clear: both;
- }
- .opengraph .flash-embedder {
- + display: -ms-flexbox;
- + display: -webkit-box;
- + display: -webkit-box-flex;
- + display: -webkit-flex;
- + display: -moz-box;
- display: flex;
- + -webkit-justify-content: center;
- justify-content: center;
- + -webkit-align-items: center;
- + -ms-flex-align: center;
- + -moz-box-align: center;
- align-items: center;
- width: 100%;
- @@ -5738,39 +5821,40 @@
- }
- .opengraph .flash-embedder .play {
- + -webkit-border-radius: 100px;
- + -moz-border-radius: 100px;
- + border-radius: 100px;
- + -webkit-transition: background-color 300ms;
- + -moz-transition: background-color 300ms;
- + -o-transition: background-color 300ms;
- + transition: background-color 300ms;
- background-color: rgba(0, 0, 0, 0.7);
- - border-radius: 100px;
- padding: 10px;
- - transition: background-color 0.3s;
- }
- .opengraph .flash-embedder:hover .play {
- background-color: #000000;
- - transition: background-color 0.3s;
- }
- .opengraph .video .flash-embedder {
- height: 200px;
- }
- -.opengraph .audio {
- - text-align: center;
- -}
- .opengraph a.info {
- + -webkit-box-sizing: border-box;
- + -moz-box-sizing: border-box;
- + box-sizing: border-box;
- + color: black;
- display: block;
- word-break: normal !important;
- - color: black;
- }
- .opengraph a.info:hover {
- color: black;
- }
- -.opengraph .info_image {
- - transition: margin, padding, width, height;
- - transition-duration: 100ms;
- - float: left;
- +.opengraph .image {
- width: 120px;
- height: 120px;
- - margin: 0px;
- + background-size: contain;
- + background-position: left center;
- + background-repeat: no-repeat;
- + display: inline-block;
- + float: left;
- margin-right: 10px;
- - padding: 0px;
- - background-size: auto 100%;
- - background-position: center center;
- - background-repeat: no-repeat;
- }
- #sort1,
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/assets/javascripts/blubber.js
- ===================================================================
- --- trunk/public/plugins_packages/core/Blubber/assets/javascripts/blubber.js (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/assets/javascripts/blubber.js (revision 35422)
- @@ -181,5 +181,5 @@
- jQuery("#posting_" + posting_id + " > .content_column .content").html(new_version.find(".content").html());
- jQuery("#posting_" + posting_id + " > .content_column .additional_tags").html(new_version.find(".additional_tags").html());
- - jQuery("#posting_" + posting_id + " > .content_column .opengraph_area").html(new_version.find(".opengraph_area").html());
- + jQuery("#posting_" + posting_id + " > .content_column .opengraph-area").html(new_version.find(".opengraph-area").html());
- if (jQuery("#posting_" + posting_id + " > .reshares").length > 0) {
- jQuery("#posting_" + posting_id + " > .reshares").html(new_version.find(".reshares").html());
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/models/BlubberPosting.class.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Blubber/models/BlubberPosting.class.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/models/BlubberPosting.class.php (revision 35422)
- @@ -22,4 +22,7 @@
- static public $hashtags_regexp = "(^|\s)\#([\w\d_\.\-\?!\+=%]*[\w\d])";
- + // Storage for formatted content for performance reasons
- + protected $formatted_content = null;
- +
- /**
- * Special format-function that adds hashtags to the common formatReady-markup.
- @@ -31,4 +34,5 @@
- $output = formatReady($text);
- StudipFormat::removeStudipMarkup("blubberhashtag");
- +
- return $output;
- }
- @@ -183,4 +187,26 @@
- $this->registerCallback('after_store', 'synchronizeHashtags');
- parent::__construct($id);
- + }
- +
- + /**
- + * @return String containing the formatted content
- + */
- + public function getContent()
- + {
- + if ($this->formatted_content === null) {
- + $content = $this->description;
- + if ($this->isThread() && $this->name && strpos($this->description, $this->name) === false) {
- + $content = $this->name . "\n" . $content;
- + }
- +
- + $this->formatted_content = self::format($content);
- + }
- +
- + return $this->formatted_content;
- + }
- +
- + public function getOpenGraphURLs()
- + {
- + return $this->getContent()->getOpenGraphURLCollection();
- }
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/views/streams/_blubber.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Blubber/views/streams/_blubber.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/views/streams/_blubber.php (revision 35422)
- @@ -137,11 +137,5 @@
- </div>
- <div class="content">
- - <?
- - $content = $thread['description'];
- - if ($thread['name'] && strpos($thread['description'], $thread['name']) === false) {
- - $content = $thread['name']."\n".$content;
- - }
- - ?>
- - <?= BlubberPosting::format($content) ?>
- + <?= $thread->getContent() ?>
- </div>
- <div class="additional_tags"><? foreach ($thread->getTags() as $tag) : ?>
- @@ -151,12 +145,5 @@
- <? endif ?>
- <? endforeach ?></div>
- - <div class="opengraph_area"><?
- - if (count(OpenGraphURL::$tempURLStorage)) {
- - $og = new OpenGraphURL(OpenGraphURL::$tempURLStorage[0]);
- - if (!$og->isNew()) {
- - echo $og->render();
- - }
- - }
- - ?></div>
- + <?= $thread->getOpenGraphURLs()->render() ?>
- </div>
- <ul class="comments"><?
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/views/streams/comment.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Blubber/views/streams/comment.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Blubber/views/streams/comment.php (revision 35422)
- @@ -47,14 +47,7 @@
- </div>
- <div class="content">
- - <?= BlubberPosting::format($posting['description']) ?>
- + <?= $posting->getContent() ?>
- </div>
- - <div class="opengraph_area"><?
- - if (count(OpenGraphURL::$tempURLStorage)) {
- - $og = new OpenGraphURL(OpenGraphURL::$tempURLStorage[0]);
- - if (!$og->isNew()) {
- - echo $og->render();
- - }
- - }
- - ?></div>
- + <?= $posting->getOpenGraphURLs()->render() ?>
- </div>
- </li>
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/models/ForumEntry.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Forum/models/ForumEntry.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/models/ForumEntry.php (revision 35422)
- @@ -88,7 +88,14 @@
- static function getContentAsHtml($description, $anonymous = false)
- {
- - $content = formatReady(ForumEntry::killEdit($description));
- + $raw_content = ForumEntry::killEdit($description);
- +
- $comment = ForumEntry::getEditComment($description, $anonymous);
- - return $content . ($comment ? '<br><i>' . htmlReady($comment) . '</i>' : '');
- + if ($comment) {
- + $raw_content .= "\n" . '%%' . $comment . '%%';
- + }
- +
- + $content = formatReady($raw_content);
- +
- + return $content;
- }
- @@ -393,5 +400,4 @@
- 'content_raw' => ForumEntry::killEdit($data['content']),
- 'content_short' => $desc_short,
- - 'opengraph' => ($og = OpenGraphURL::find(OpenGraphURL::$tempURLStorage[0])) ? $og->render() : "",
- 'chdate' => $data['chdate'],
- 'mkdate' => $data['mkdate'],
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/models/ForumHelpers.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Forum/models/ForumHelpers.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/models/ForumHelpers.php (revision 35422)
- @@ -31,5 +31,7 @@
- {
- foreach ($highlight as $hl) {
- - $text = str_ireplace(htmlReady($hl), '<span class="highlight">'. htmlReady($hl) .'</span>', $text);
- + $text = preg_replace('/' . preg_quote(htmlReady($hl), '/') . '/i',
- + '<span class="highlight">$0</span>',
- + $text);
- }
- return $text;
- @@ -46,5 +48,7 @@
- function highlight($text, $highlight)
- {
- - if (empty($highlight)) return $text;
- + if (empty($highlight)) {
- + return $text;
- + }
- $data = array();
- Index: dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/views/index/_post.php
- ===================================================================
- --- trunk/public/plugins_packages/core/Forum/views/index/_post.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/public/plugins_packages/core/Forum/views/index/_post.php (revision 35422)
- @@ -91,7 +91,7 @@
- <span data-show-topic="<?= $post['topic_id'] ?>" data-topic-content="<?= $post['topic_id'] ?>" <?= $edit_posting != $post['topic_id'] ? '' : 'style="display: none;"' ?>>
- <?= ForumHelpers::highlight($post['content'], $highlight) ?>
- + <?= $post['content']->getOpenGraphURLCollection()->render() ?>
- </span>
- </div>
- - <div class="opengraph_area"><?= $post['opengraph'] ?></div>
- <!-- Buttons for this Posting -->
- Index: dev-branches/tic6013-opengraph/templates/shared/opengraph-container.php
- ===================================================================
- --- dev-branches/tic6013-opengraph/templates/shared/opengraph-container.php (revision 35422)
- +++ dev-branches/tic6013-opengraph/templates/shared/opengraph-container.php (revision 35422)
- @@ -0,0 +1,5 @@
- +<div class="opengraph-area">
- +<? foreach ($urls as $url): ?>
- + <?= $url ?>
- +<? endforeach; ?>
- +</div>
- Index: dev-branches/tic6013-opengraph/templates/shared/opengraphinfo_wide.php
- ===================================================================
- --- trunk/templates/shared/opengraphinfo_wide.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/templates/shared/opengraphinfo_wide.php (revision 35422)
- @@ -1,62 +1,51 @@
- <? $videofiles = $og->getVideoFiles() ?>
- <? $audiofiles = $og->getAudioFiles() ?>
- -<div class="opengraph<?= count($videofiles) > 0 ? " video" : "" ?>">
- +<div class="opengraph <? if (count($videofiles) > 0) echo 'video'; ?> <? if (count($audiofiles) > 0) echo 'audio'; ?>">
- +<? if ($og['image'] && count($videofiles) === 0): ?>
- + <a href="<?= URLHelper::getLink($og['url'], array(), false) ?>" class="image" target="_blank"
- + style="background-image:url(<?= $og['image'] ?>)">
- + </a>
- +<? endif; ?>
- <a href="<?= URLHelper::getLink($og['url'], array(), false) ?>" class="info" target="_blank">
- - <? if ($og['image'] && !count($videofiles)) : ?>
- - <div class="info_image" style="background-image: url('<?= htmlReady($og['image']) ?>');">
- - </div>
- - <? endif ?>
- <strong><?= htmlReady($og['title']) ?></strong>
- - <? if (!count($videofiles)) : ?>
- - <p>
- - <?= htmlReady($og['description']) ?>
- - </p>
- - <? endif ?>
- + <? if (!count($videofiles)) : ?>
- + <p><?= htmlReady($og['description']) ?></p>
- + <? endif ?>
- </a>
- - <? if (count($videofiles)) : ?>
- +<? if (count($videofiles)) : ?>
- <div class="video">
- - <? if (in_array($videofiles[0][1], array("text/html", "application/x-shockwave-flash"))) : ?>
- - <?
- - $embedder = '<iframe width="100%" height="200px" frameborder="0" src="'. htmlReady($videofiles[0][0]).'"></iframe>';
- - ?>
- - <a href="#"
- - class="flash-embedder"
- - style="background-image: url('<?= htmlReady($og['image']) ?>');"
- - onClick="jQuery(this).replaceWith(jQuery(this).data('embedder')); return false;"
- - data-embedder="<?= htmlReady($embedder) ?>"
- - title="<?= _("Video abspielen") ?>">
- - <?= Assets::img("icons/80/blue/play.svg", array('class' => "play"))?>
- - </a>
- - <? else : ?>
- + <? if (in_array($videofiles[0][1], array("text/html", "application/x-shockwave-flash"))) : ?>
- + <a href="<?= htmlReady($videofiles[0][0]) ?>"
- + class="flash-embedder"
- + style="background-image: url('<?= htmlReady($og['image']) ?>');"
- + title="<?= _("Video abspielen") ?>">
- + <?= Assets::img("icons/80/blue/play.svg", array('class' => "play"))?>
- + </a>
- + <? else : ?>
- <video width="100%" height="200px" controls>
- - <? foreach ($videofiles as $file) : ?>
- + <? foreach ($videofiles as $file) : ?>
- <source src="<?= htmlReady($file[0]) ?>"<?= $file[1] ? ' type="'.htmlReady($file[1]).'"' : "" ?>></source>
- - <? endforeach ?>
- + <? endforeach ?>
- </video>
- - <? endif ?>
- + <? endif ?>
- </div>
- +<? endif ?>
- +<? if (count($audiofiles)) : ?>
- + <div class="audio">
- + <? if (in_array($audiofiles[0][1], array("text/html", "application/x-shockwave-flash"))) : ?>
- + <a href="<?= htmlReady($audiofiles[0][0]) ?>"
- + class="flash-embedder"
- + style="background-image: url('<?= htmlReady($og['image']) ?>');"
- + title="<?= _("Audio abspielen") ?>">
- + <?= Assets::img("icons/100/blue/play.svg")?>
- + </a>
- + <? else : ?>
- + <audio width="100%" height="50px" controls>
- + <? foreach ($audiofiles as $file) : ?>
- + <source src="<?= htmlReady($file[0]) ?>"<?= $file[1] ? ' type="'.htmlReady($file[1]).'"' : "" ?>></source>
- + <? endforeach ?>
- + </audio>
- <? endif ?>
- - <? if (count($audiofiles)) : ?>
- - <div class="audio">
- - <? if (in_array($audiofiles[0][1], array("text/html", "application/x-shockwave-flash"))) : ?>
- - <?
- - $embedder = '<iframe width="100%" height="200px" frameborder="0" src="'. htmlReady($audiofiles[0][0]).'"></iframe>';
- - ?>
- - <a href="#"
- - class="flash-embedder"
- - style="background-image: url('<?= htmlReady($og['image']) ?>');"
- - onClick="jQuery(this).replaceWith(jQuery(this).data('embedder')); return false;"
- - data-embedder="<?= htmlReady($embedder) ?>"
- - title="<?= _("Audio abspielen") ?>">
- - <?= Assets::img("icons/100/blue/play.svg")?>
- - </a>
- - <? else : ?>
- - <audio width="100%" height="50px" controls>
- - <? foreach ($audiofiles as $file) : ?>
- - <source src="<?= htmlReady($file[0]) ?>"<?= $file[1] ? ' type="'.htmlReady($file[1]).'"' : "" ?>></source>
- - <? endforeach ?>
- - </audio>
- - <? endif ?>
- </div>
- - <? endif ?>
- +<? endif ?>
- </div>
- Index: dev-branches/tic6013-opengraph/tests/unit/lib/VisualTest.php
- ===================================================================
- --- trunk/tests/unit/lib/VisualTest.php (revision 35413)
- +++ dev-branches/tic6013-opengraph/tests/unit/lib/VisualTest.php (revision 35422)
- @@ -12,6 +12,13 @@
- require_once dirname(__FILE__) . '/../bootstrap.php';
- require_once 'config.inc.php'; //$SMILE_SHORT and $SYMBOL_SHORT needed by formatReady
- +require_once 'lib/classes/StudipArrayObject.class.php';
- +require_once 'lib/classes/MultiDimArrayObject.class.php';
- +require_once 'lib/classes/JSONArrayObject.class.php';
- require_once 'lib/models/SimpleORMap.class.php';
- +require_once 'lib/models/SimpleCollection.class.php';
- +require_once 'lib/models/SimpleORMapCollection.class.php';
- require_once 'lib/models/OpenGraphURL.class.php';
- +require_once 'lib/models/OpenGraphURLCollection.class.php';
- +require_once 'lib/classes/FormattedContent.php';
- require_once 'lib/visual.inc.php';
- require_once 'lib/classes/Config.class.php';
- @@ -23,5 +30,6 @@
- {
- static $config = array(
- - 'LOAD_EXTERNAL_MEDIA' => 'allow'
- + 'LOAD_EXTERNAL_MEDIA' => 'allow',
- + 'OPENGRAPH_ENABLE' => false,
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement