Permalink
Browse files

add subscriber hook capability for item display only. closes #2. also…

… fix parent category link from user item display view.
  • Loading branch information...
craigh committed Jun 10, 2011
1 parent f5aaa6f commit f05c3945ee3acd1fb1c6d5dd6819dea5a28900f0
@@ -1,4 +1,5 @@
<?php
+
/**
* Downloads
*
@@ -10,6 +11,7 @@
*/
class Downloads_Installer extends Zikula_AbstractInstaller
{
+
/**
* Initializes a new install
*
@@ -27,16 +29,18 @@ public function install()
} catch (Exception $e) {
return false;
}
-
+
// Set up config variables
$this->setVars(Downloads_Util::getModuleDefaults());
$this->createUploadDir();
$cid = $this->createSampleCategory();
$this->createSampleDownload($cid);
+ HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
+
return true;
}
-
+
/**
* Upgrades an old install
*
@@ -50,7 +54,7 @@ public function install()
public function upgrade($oldversion)
{
$this->throwForbiddenUnless(SecurityUtil::checkPermission('Downloads::', '::', ACCESS_ADMIN), LogUtil::getErrorMsgPermission());
-
+
switch ($oldversion) {
case '2.4':
case '2.4.0':
@@ -81,21 +85,23 @@ public function upgrade($oldversion)
$newVars['upload_folder'] = substr($newVars['upload_folder'], 0, -1);
}
$this->setVars($newVars);
-
+
// update url field for each row to include upload dir
// and rename from ID to name
$this->updateRows();
// drop old modrequest table
DoctrineUtil::dropTable('downloads_modrequest');
-
+
+ HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
+
case '3.0.0':
- //future development
+ //future development
}
-
+
return true;
}
-
+
/**
* removes an install
*
@@ -110,17 +116,19 @@ public function uninstall()
// drop table
DoctrineUtil::dropTable('downloads_downloads');
DoctrineUtil::dropTable('downloads_categories');
-
+
//remove files from data folder
$uploaddir = DataUtil::formatForOS($this->getVar('upload_folder'));
FileUtil::deldir($uploaddir, true);
-
+
// remove all module vars
$this->delVars();
+
+ HookUtil::unregisterSubscriberBundles($this->version->getHookSubscriberBundles());
return true;
}
-
+
/**
* Upload directory creation
*/
@@ -135,7 +143,7 @@ private function createUploadDir()
return $uploaddir;
}
-
+
/**
* List of ModVars that previously (<= v2.4) were stored as strings: Yes/No
* @return array
@@ -158,7 +166,7 @@ private function getCheckedVars()
'torrent', //
);
}
-
+
/**
* Create a sample category
* @return int created category id
@@ -176,7 +184,7 @@ private function createSampleCategory()
$cat->save();
return $cat['cid'];
}
-
+
/**
* Create a sample download
* @param type $cid
@@ -196,12 +204,12 @@ private function createSampleDownload($cid)
"update" => date("Y-m-d H:i:s"),
"date" => date("Y-m-d H:i:s"),
);
-
+
$file = new Downloads_Model_Download();
$file->merge($data);
$file->save();
}
-
+
/**
* Update all rows so url is properly formatted
*/
@@ -218,23 +226,23 @@ private function updateRows()
$filenameParts = explode('.', $row['filename']);
$newname = DataUtil::formatForURL($filenameParts[0]) . '.' . array_pop($filenameParts);
$newurl = "$path/$newname";
- $oldurl = $path . '/' .$row['url'];
+ $oldurl = $path . '/' . $row['url'];
if (@rename(DataUtil::formatForOS($oldurl), DataUtil::formatForOS($newurl))) {
// update DB
$tbl->createQuery()
- ->update()
- ->set('url', '?', $newurl)
- ->set('filename', '?', $newname)
- ->where('lid = ?', $row['lid'])
- ->execute();
+ ->update()
+ ->set('url', '?', $newurl)
+ ->set('filename', '?', $newname)
+ ->where('lid = ?', $row['lid'])
+ ->execute();
} else {
// update DB
$tbl->createQuery()
- ->update()
- ->set('url', '?', $oldurl)
- ->set('filename', '?', $newname)
- ->where('lid = ?', $row['lid'])
- ->execute();
+ ->update()
+ ->set('url', '?', $oldurl)
+ ->set('filename', '?', $newname)
+ ->where('lid = ?', $row['lid'])
+ ->execute();
}
} else {
// this section simply renames filenames to only have one extension
@@ -244,12 +252,15 @@ private function updateRows()
$newname = DataUtil::formatForURL($filenameParts[0]) . '.' . array_pop($filenameParts);
// update DB
$tbl->createQuery()
- ->update()
- ->set('filename', '?', $newname)
- ->where('lid = ?', $row['lid'])
- ->execute();
+ ->update()
+ ->set('filename', '?', $newname)
+ ->where('lid = ?', $row['lid'])
+ ->execute();
}
}
}
}
-} // end class def
+
+}
+
+// end class def
@@ -24,8 +24,15 @@ public function getMetaData()
'Downloads::Category' => 'CategoryID::',
'Downloads::Item' => 'ID::');
$meta['core_min'] = '1.3.0'; // requires minimum 1.3.0 or later
+ $meta['capabilities'] = array(HookUtil::SUBSCRIBER_CAPABLE => array('enabled' => true));
return $meta;
}
-
+
+ protected function setupHookBundles()
+ {
+ $bundle = new Zikula_HookManager_SubscriberBundle($this->name, 'subscriber.downloads.ui_hooks.downloads', 'ui_hooks', $this->__('Downloads Hooks'));
+ $bundle->addEvent('display_view', 'downloads.ui_hooks.downloads.display_view');
+ $this->registerHookSubscriberBundle($bundle);
+ }
}
@@ -24,8 +24,9 @@
</ul>
<br />
<a href="{modurl modname="Downloads" type="user" func="view"}">{img modname='core' set='icons/medium' src='folder_red.png' __title='Root category' __alt='Root category' class='z-middle tooltips'}&nbsp;&nbsp;{gt text='Back to Root category'}</a>
- <a href="{modurl modname="Downloads" type="user" func="view" cid=$item.cid}">{img modname='core' set='icons/medium' src='folder_blue.png' __title='Category' __alt='Category' class='z-middle tooltips'}&nbsp;&nbsp;{gt text="Back to category '%s'" tag1=$item.cid|getcategorynamefromid|safetext}</a>
+ <a href="{modurl modname="Downloads" type="user" func="view" category=$item.cid}">{img modname='core' set='icons/medium' src='folder_blue.png' __title='Category' __alt='Category' class='z-middle tooltips'}&nbsp;&nbsp;{gt text="Back to category '%s'" tag1=$item.cid|getcategorynamefromid|safetext}</a>
</div>
+{notifydisplayhooks eventname='downloads.ui_hooks.downloads.display_view' id=$item.lid}
<script type="text/javascript">
// <![CDATA[
Zikula.UI.Tooltips($$('.tooltips'));

0 comments on commit f05c394

Please sign in to comment.