Skip to content
Permalink
Browse files

added picture ordering; updates #940

  • Loading branch information...
following5 committed Mar 19, 2016
1 parent 445d411 commit f169175ece878db89773745b1f619b98bc0e1cf2
@@ -841,6 +841,43 @@ function dbv_153() // generic trigger update, see notes on "maintain.php update
update_triggers();
}
function dbv_154() // add pictures order option
{
if (!sql_field_exists('pictures', 'seq')) {
sql("ALTER TABLE `pictures` ADD COLUMN `seq` smallint(5) NOT NULL default '0'");
}
// initialize the new ordering field
if (sql_value("SELECT COUNT(*) from `pictures` WHERE `seq`=0", 0))
{
$rs = sql("
SELECT `id`, `object_type`, `object_id`
FROM `pictures`
ORDER BY `object_type`, `object_id`, `date_created`");
$prev_object_type = -1;
$prev_object_id = -1;
// Prevent updating pictures.last_modified for the case that
// the new triggers are already installed:
sql("SET @XMLSYNC=1");
while ($r = sql_fetch_assoc($rs))
{
if ($r['object_type'] != $prev_object_type ||
$r['object_id'] != $prev_object_id)
$seq = 1;
sql("UPDATE `pictures` SET `seq`='&2' WHERE `id`='&1'", $r['id'], $seq);
++$seq;
$prev_object_type = $r['object_type'];
$prev_object_id = $r['object_id'];
}
sql("SET @XMLSYNC=0");
sql_free_result($rs);
}
sql("ALTER TABLE `pictures` DROP INDEX `object_type`,
ADD UNIQUE INDEX `object_type` (`object_type`,`object_id`,`seq`)");
}
// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
//
@@ -2865,6 +2865,7 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2604', 'Admin<b
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2605', 'If you are sure that the geocache is gone, and the owner does not<br />react to your log entry, you may report it to the Opencaching team.<br />Use the \'Report this cache\' button above the cache description.', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2606', 'Picture', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2607', 'Title:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2608', 'move up', '2015-06-17 10:09:14');

-- Table sys_trans_ref
SET NAMES 'utf8';
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2605', 'DE', 'Wenn du sicher bist, dass der Cache nicht mehr da ist, und der Besitzer <br />nicht auf dein Log reagiert, kannst du eine Meldung an das Opencaching-<br />Team senden. Verwende dazu den Knopf \'Cache melden\' oberhalb der <br />Cachebeschreibung.', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2606', 'DE', 'Bild', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2607', 'DE', 'Titel:', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2608', 'DE', 'nach oben', '2015-06-17 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing – please do not login', '2010-08-28 11:48:07');
@@ -1503,6 +1503,7 @@
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
SET NEW.`date_created`=NOW();
SET NEW.`last_modified`=NOW();
SET NEW.`seq`= IFNULL((SELECT MAX(`seq`)+1 FROM `pictures` WHERE `object_type`=NEW.`object_type` AND `object_id`=NEW.`object_id`), 1);
END IF;
IF ISNULL(NEW.`uuid`) OR NEW.`uuid`='' THEN
@@ -1547,7 +1548,8 @@
NEW.`local`!=OLD.`local` OR
NEW.`unknown_format`!=OLD.`unknown_format` OR
NEW.`display`!=OLD.`display` OR
NEW.`mappreview`!=OLD.`mappreview` THEN
NEW.`mappreview`!=OLD.`mappreview` OR
NEW.`seq`!=OLD.`seq` THEN
/* everything except last_url_check, thumb_url and thumb_last_generated */
SET NEW.`last_modified`=NOW();
END IF;
@@ -18,8 +18,9 @@ CREATE TABLE `pictures` (
`unknown_format` tinyint(1) NOT NULL default '0',
`display` tinyint(1) NOT NULL default '1',
`mappreview` tinyint(1) NOT NULL default '0',
`seq` smallint(5) NOT NULL default '0'
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `last_modified` (`last_modified`),
KEY `object_type` (`object_type`,`object_id`)
UNIQUE KEY `object_type` (`object_type`,`object_id`,`seq`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
@@ -71,6 +71,7 @@ <h2>Änderungen in Version 1.5 (März 2016)</h2>
<li>nccom-Attribut entfernt</li>
<li>Bei Caches wird zusätzlich das Attribut <em>gccom2</em> ausgegeben. Es enthält vom Opencaching-Team handgewartete GC-Wegpunkte.</li>
<li>Beim Cachestatus und beim Logtyp weden die zusätzlichen Attribute <em>needs_maintenance</em> und <em>listing_oudated</em> ausgegeben, also die logbaren Wartungszustände. Bei Caches hat es den Wert 0 (Cache ok) oder 1 (benötigt Wartung), bei Logs den Wert 0 (keine Angabe), 1 (Cache ok) oder 2 (benötigt Wartung).</li>
<li>Bei Bildern wird das zusätzliche Element &lt;position&gt; ausgegeben. Es enthält die Position des Bildes in der Liste der Bilder eines Caches oder Logs, beginnend mit 1.</li>
</ul>

<p>Der XML-Doctype lautet in allen Versionen "oc11xml".</p>
@@ -892,11 +892,11 @@ function getWaypoints($cacheid)
if ($cache_record['picture'] > 0)
{
$pictures = '';
$rspictures = sql("SELECT `url`, `title`, `uuid` FROM `pictures` WHERE `object_id`='&1' AND `object_type`=2", $cache_id);
$rspictures = sql("SELECT `url`, `title`, `uuid` FROM `pictures` WHERE `object_id`='&1' AND `object_type`=2 ORDER BY `seq`", $cache_id);
for ($i = 0; $i < mysql_num_rows($rspictures); $i++)
{
$tmpline = $pictureline;
$tmpline = ($i == 0 ? $pictureline0 : $pictureline);
$pic_record = sql_fetch_array($rspictures);
$tmpline = mb_ereg_replace('{link}', htmlspecialchars($pic_record['url'], ENT_COMPAT, 'UTF-8'), $tmpline);
@@ -22,7 +22,7 @@
$tpl->assign('cachename', $rCache['name']);
$rsPictures = sql('SELECT `uuid`, `url`, `title` FROM `pictures` WHERE `object_id`=&1 AND `object_type`=2', $cacheid);
$rsPictures = sql('SELECT `uuid`, `url`, `title` FROM `pictures` WHERE `object_id`=&1 AND `object_type`=2 ORDER BY `seq`', $cacheid);
$pictures = array();
while ($rPicture = sql_fetch_assoc($rsPictures))
{
@@ -35,7 +35,8 @@
$safari_not_allowed_message = '<span class="errormsg">' . t('Only virtual caches can be safari caches.') . '</span>';
$bad_wpgc_message = '<span class="errormsg">' . t('GC waypoint is invalid, must be GCxxxxx') . '</span>';
$nopictures = '<tr><td colspan="2">' . t('No pictures available') . '</td></tr><tr><td colspan="2">&nbsp;</td></tr>';
$pictureline = '<tr><td colspan="2"><a href="{link}">{title}</a> [<a href="picture.php?action=edit&uuid={uuid}">' . t('Edit') . '</a>] [<a href="picture.php?action=delete&uuid={uuid}">' . t('Delete') . '</a>]</td></tr>';
$pictureline0 = '<tr><td colspan="2"><a href="{link}">{title}</a> [<a href="picture.php?action=edit&uuid={uuid}">' . t('edit') . '</a>] [<a href="picture.php?action=delete&uuid={uuid}">' . t('delete') . '</a>]</td></tr>';
$pictureline = '<tr><td colspan="2"><a href="{link}">{title}</a> [<a href="picture.php?action=edit&uuid={uuid}">' . t('edit') . '</a>] [<a href="picture.php?action=up&uuid={uuid}" title="' . t('move up') . '">&#x25B2;</a>] [<a href="picture.php?action=delete&uuid={uuid}">' . t('delete') . '</a>]</td></tr>';
// Ocprop: <a href=\"http://.*?\.opencaching\.de/images/uploads/.*?\">(.*?)<\/a>.*?\[<a href=\"picture\.php\?action=[a-z]*?\&uuid=(.*?)\">
$picturelines = '{lines}<tr><td colspan="2">&nbsp;</td></tr>';
$gc_com_msg2 = t('To prevent any problems with geocaching.com we want to please you to upload all linked pictures to %1 as well and link the pictures in the HTML code to these on %1');
@@ -423,7 +423,8 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_
$rsPictures = sql("
SELECT `url`, `title`, `uuid`, `id`, `spoiler`
FROM `pictures`
WHERE `object_id`='&1' AND `object_type`=1",
WHERE `object_id`='&1' AND `object_type`=1
ORDER BY `seq`",
$rLog['id']);
while ($rPicture = sql_fetch_assoc($rsPictures))
{
@@ -55,6 +55,7 @@ function __construct($nNewPictureId=ID_NEW)
$this->rePicture->addInt('unknown_format', 0, false);
$this->rePicture->addInt('display', 1, false);
$this->rePicture->addInt('mappreview', 0, false);
$this->rePicture->addInt('seq', 1, false);
$this->nPictureId = $nNewPictureId+0;
@@ -350,6 +351,10 @@ function getDateCreated()
{
return $this->rePicture->getValue('date_created');
}
function getPosition()
{
return $this->rePicture->getValue('seq');
}
function getAnyChanged()
{
return $this->rePicture->getAnyChanged();
@@ -585,5 +590,54 @@ function imagick_rotate(&$image)
return false;
}
function up()
{
$prevpos = sql_value("
SELECT MAX(`seq`)
FROM `pictures`
WHERE `object_type`='&1' AND `object_id`='&2' AND `seq`<'&3'",
0,
$this->getObjectType(),
$this->getObjectId(),
$this->getPosition());
if ($prevpos)
{
$maxpos = sql_value("
SELECT MAX(`seq`)
FROM `pictures`
WHERE `object_type`='&1' AND `object_id`='&2'",
0,
$this->getObjectType(),
$this->getObjectId());
// swap positions with the previous pic
sql("
UPDATE `pictures`
SET `seq`='&2'
WHERE `id`='&1'",
$this->getPictureId(),
$maxpos + 1);
sql("
UPDATE `pictures` SET `seq`='&4'
WHERE `object_type`='&1' AND `object_id`='&2' AND `seq`='&3'",
$this->getObjectType(),
$this->getObjectId(),
$prevpos,
$this->getPosition());
sql("
UPDATE `pictures`
SET `seq`='&2'
WHERE `id`='&1'",
$this->getPictureId(),
$prevpos);
$this->rePicture->setValue('seq', $prevpos);
return true;
}
return false;
}
}
?>
@@ -564,7 +564,7 @@ function getPictures($cacheid, $server_address)
SELECT `uuid`, `title`, `url`, `spoiler`
FROM `pictures`
WHERE `object_id`='&1' AND `object_type`=2 AND `display`=1
ORDER BY `date_created`",
ORDER BY `seq`",
$cacheid
);
while ($r = sql_fetch_array($rs))
@@ -33,6 +33,8 @@
$tpl->assign('action', $action);
$tpl->assign('redirect', $redirect);
$uuid = isset($_REQUEST['uuid']) ? $_REQUEST['uuid'] : 0;
if ($action == 'add') // Ocprop
{
$picture = new picture();
@@ -162,7 +164,6 @@
}
else if ($action == 'edit' || $action == 'delete')
{
$uuid = isset($_REQUEST['uuid']) ? $_REQUEST['uuid'] : 0;
$picture = picture::fromUUID($uuid);
if ($picture === null)
@@ -206,6 +207,19 @@
else
$tpl->error(ERROR_INVALID_OPERATION);
}
else if ($action == 'up')
{
$picture = picture::fromUUID($uuid);
if ($picture === null)
$tpl->error(ERROR_PICTURE_NOT_EXISTS);
if ($redirect == '')
$redirect = $picture->getPageLink();
$picture->up();
$tpl->redirect($redirect);
}
else
$tpl->error(ERROR_INVALID_OPERATION);
@@ -95,6 +95,7 @@
{if $logItem.userid==$login.userid}
&nbsp;
[<a href="picture.php?action=edit&uuid={$pictureItem.uuid|escape}">{t}Edit{/t}</a>]
{if !$smarty.foreach.pictures.first}[<a href="picture.php?action=up&uuid={$pictureItem.uuid|escape}" title="{t}move up{/t}">&#x25B2;</a>]{/if}
[<a href="javascript:if(confirm('{t escape=js}Do you really want to delete this picture?{/t}'))location.href='picture.php?action=delete&uuid={$pictureItem.uuid|escape}'">{t}Delete{/t}</a>]
{/if}
<br />
@@ -212,7 +212,7 @@ function getChildWaypoints($cacheid)
$tpl->assign('coordinates', $coord->getDecimalMinutes());
// pictures
$rs = sql("SELECT `id`, `uuid`, `url`, `title`, `thumb_url`, `spoiler`, `display` FROM `pictures` WHERE `object_type`=2 AND `object_id`='&1' AND `display`!=0 ORDER BY `date_created` ASC", $cacheid);
$rs = sql("SELECT `id`, `uuid`, `url`, `title`, `thumb_url`, `spoiler`, `display` FROM `pictures` WHERE `object_type`=2 AND `object_id`='&1' AND `display`!=0 ORDER BY `seq`", $cacheid);
$tpl->assign_rs('pictures', $rs);
sql_free_result($rs);
@@ -667,7 +667,7 @@ function outputXmlFile($sessionid, $filenr, $bXmlDecl, $bOcXmlTag, $bDocType, $z
`pictures`.`date_created` `date_created`, `pictures`.`uuid` `uuid`,
`pictures`.`last_modified` `last_modified`, `pictures`.`display` `display`,
`pictures`.`spoiler` `spoiler`, `pictures`.`node` `node`,
`pictures`.`mappreview`,
`pictures`.`mappreview`, `pictures`.`seq`,
IFNULL(`c1`.`cache_id`,`c2`.`cache_id`) AS `cache_id`,
IFNULL(`c1`.`country`,`c2`.`country`) AS `language`, /* hack */
IFNULL(`cs1`.`allow_user_view`, `cs2`.`allow_user_view`) AS `auv`,
@@ -698,6 +698,7 @@ function outputXmlFile($sessionid, $filenr, $bXmlDecl, $bOcXmlTag, $bDocType, $z
fwrite($f, $t2 . '<attributes spoiler="' . $r['spoiler'] . '" display="' . $r['display'] . '" />' . "\n");
fwrite($f, $t2 . '<datecreated>' . date($sDateformat, strtotime($r['date_created'])) . '</datecreated>' . "\n");
fwrite($f, $t2 . '<lastmodified>' . date($sDateformat, strtotime($r['last_modified'])) . '</lastmodified>' . "\n");
fwrite($f, $t2 . '<position>' . $r['seq'] . '</position>' . "\n");
if ($bLicense)
{
@@ -10,7 +10,7 @@
<!ELEMENT cache (id, userid, name, longitude, latitude, type, status, country, size, desclanguages, difficulty, terrain, rating, waypoints, datehidden, datecreated, lastmodified, listing_lastmodified, attributes, wpts)>
<!ELEMENT cachedesc (id, cacheid, language, shortdesc, desc, hint, license?, lastmodified)>
<!ELEMENT cachelog (id, cacheid, userid, logtype, date, text, license?, datecreated, lastmodified, log_lastmodified)>
<!ELEMENT picture (id, url, title, object, picattr, license?, datecreated, lastmodified)>
<!ELEMENT picture (id, url, title, object, picattr, license?, datecreated, lastmodified, position)>
<!ELEMENT removedobject (id, object, removeddate)>

<!-- common elements -->
@@ -145,6 +145,7 @@
display CDATA #REQUIRED
preview CDATA #IMPLIED
>
<!ELEMENT position (#PCDATA)>

<!-- removedobject -->

0 comments on commit f169175

Please sign in to comment.
You can’t perform that action at this time.