Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Updated api encode/decodeurl to use the urltitle removing the pid. Refs
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Dec 20, 2011
1 parent 515bd2b commit 1dc0aa4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
57 changes: 39 additions & 18 deletions src/modules/Clip/lib/Clip/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,28 +605,34 @@ public function encodeurl($args)
$id = (int)$_['id'];
if (!isset($pid)) {
if (!isset($cache['id'][$tid][$id])) {
$pid = $cache['id'][$tid][$id] = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)
->selectFieldBy('core_pid', $id, 'id');
$pub = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)->findOneBy('id', $id);
$pid = $cache['id'][$tid][$id] = $pub['core_pid'];
$cache['urltitle'][$tid][$pid] = $pub['core_urltitle'];
} else {
$pid = $cache['id'][$tid][$id];
}
}
} elseif (isset($_['urltitle']) && !isset($pid)) {
$pid = $cache['id'][$tid][$id] = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)
->selectFieldBy('core_pid', $_['urltitle'], 'core_urltitle', 'core_online DESC');
if (!$pid) {
return false;
}
}

if ($pid) {
// not submit (pid: 0)
if (isset($cache['title'][$tid][$pid])) {
$urltitle = $cache['title'][$tid][$pid];
} elseif (isset($_['title']) && !empty($_['title'])) {
$urltitle = $_['title'];
if (isset($cache['urltitle'][$tid][$pid])) {
$urltitle = $cache['urltitle'][$tid][$pid];
} elseif (isset($_['urltitle']) && !empty($_['urltitle'])) {
$urltitle = $_['urltitle'];
} else {
$urltitle = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)
->selectFieldBy(Clip_Util::getPubType($tid)->getTitleField(), $pid, 'core_pid');
$urltitle = DataUtil::formatPermalink($urltitle);
->selectFieldBy('core_urltitle', $pid, 'core_pid');
}
$cache['title'][$tid][$pid] = $urltitle;
$cache['urltitle'][$tid][$pid] = $urltitle;

$urltitle = "/$urltitle.$pid" . (isset($id) ? ".$id" : '');
$urltitle = "/$urltitle" . (isset($id) ? "~$id" : '');
$shorturl .= $urltitle . ($tpl ? ".$tpl" : '');
}

Expand Down Expand Up @@ -675,7 +681,7 @@ public function decodeurl($args)
// reset the function to main
System::queryStringSetVar('func', 'main');

if (!preg_match('/^([a-z0-9_\-]+?)(\.([a-z0-9_\.\-]+))?$/i', end($_), $matches)) {
if (!preg_match('/^([a-z0-9_\-\~]+?)(\.([a-z0-9_\.\-]+))?$/i', end($_), $matches)) {
// there must be a valid filename
return true;
}
Expand Down Expand Up @@ -770,20 +776,35 @@ public function decodeurl($args)

case 'display':
$s = preg_quote(System::getVar('shorturlsseparator'), '~');

if (!isset($pubtitle)) {
// by now, the pub still has the pid/id as suffix
$fullstr = "$filename.$template";
preg_match('/^([a-z0-9_\-'.$s.']+?\.[\d]+?(\.[\d]+)?)(\.([a-z0-9_\.\-]+))?$/i', $fullstr, $matches);
// by now, the pub still has the id as suffix
preg_match('/^([a-z0-9_\-'.$s.']+?(\~[\d]+)?)$/i', $filename, $matches);

$pubtitle = $matches[1];
$template = isset($matches[4]) ? $matches[4] : null;
}

// extract the pid/id
if (preg_match('~^[a-z0-9_\-'.$s.']+\.(\d+?)(\.(\d+))?$~i', $pubtitle, $matches)) {
System::queryStringSetVar('pid', $matches[1]);
// extract the urltitle[~id]
if (preg_match('~^([a-z0-9_\-'.$s.']+?)(\~(\d+))?$~i', $pubtitle, $matches)) {
$where = array();

if (isset($matches[3])) {
$where[] = array('id = ?', $matches[3]);

System::queryStringSetVar('id', $matches[3]);
}

$where[] = array('core_urltitle = ?', $matches[1]);

$pid = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)
->selectField('core_pid', $where);

// invalid urltitle~id combination
if (!$pid) {
return false;
}

System::queryStringSetVar('pid', $pid);
}
break;
}
Expand Down
7 changes: 6 additions & 1 deletion src/modules/Clip/templates/plugins/function.clip_url.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function smarty_function_clip_url($params, Zikula_View &$view)
return false;
}

if (isset($params['pub']) && !$params['pub'] instanceof Clip_Doctrine_Pubdata && !is_array($params['pub'])) {
$view->trigger_error($view->__f('Error! in %1$s: the %2$s parameter is not valid.', array('clip_url', 'pub')));
return false;
}

$assign = isset($params['assign']) ? $params['assign'] : null;
unset($params['assign']);

Expand All @@ -56,7 +61,7 @@ function smarty_function_clip_url($params, Zikula_View &$view)
if ($params['func'] == 'edit') {
$params['id'] = $params['pub']['id'];
}
$params['title'] = DataUtil::formatPermalink($params['pub']['core_title']);
$params['urltitle'] = $params['pub']['core_urltitle'];
}
unset($params['pub']);
}
Expand Down

0 comments on commit 1dc0aa4

Please sign in to comment.