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

[WIP] Hooks #301

Merged
merged 13 commits into from
Mar 8, 2017
38 changes: 38 additions & 0 deletions Command/mailcron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Dizkus
*
* @copyright (c) 2001-now, Dizkus Development Team
* @see https://github.com/zikula-modules/Dizkus
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
*/

//
// This file was most probably called by os cron
// If so this should be moved
//

//
// store the absolute path to your Zikula folder here
//
//chdir('/opt/webdev/htdocs');
////
//// no changes necessary beyond this point!
////
//include 'lib/ZLoader.php';
//ZLoader::register();
//System::init();
//$debug = $this->request->query->get('debug', $this->request->request->get('debug', 0));
//$debug = $debug == 1 ? true : false;
//// user userId = 2 (site owner) to avoid perm limits
//$forums = ModUtil::apiFunc('ZikulaDizkusModule', 'forum', 'getForumIdsByPermission', array('userId' => 2));
//if (is_array($forums) && count($forums) > 0) {
// echo count($forums) . ' forums read<br />';
// foreach ($forums as $forum) {
// if ($forum['externalsource'] == 1) {
// // Mail
// ModUtil::apiFunc('ZikulaDizkusModule', 'cron', 'mail', array('forum' => $forum, 'debug' => $debug));
// }
// }
//}
12 changes: 7 additions & 5 deletions rss2dizkus.php → Command/rss2dizkus.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,23 @@
$lastuser = $connection['coreUser']->getUid();
$loggedin = true;
} else {
//something should happend here?
}
} else {
// we have been here before
$loggedin = true;
}
if ($loggedin == true) {
$rss = ModUtil::apiFunc('Feeds', 'user', 'get', [
'fid' => $connection['server']]);
'fid' => $connection['server']]);
if (!$rss) {
// this feed does not exist
die;
}
// Get the feed
$dump = ModUtil::apiFunc('Feeds', 'user', 'getfeed', [
'fid' => $rss['fid'],
'url' => $rss['url']]);
'fid' => $rss['fid'],
'url' => $rss['url']]);
if (!$dump) {
// this feed does not exist
die;
Expand All @@ -83,9 +84,10 @@
$items = $dump['feed']->get_items();
// See the function below...
$insert = ModUtil::apiFunc('ZikulaDizkusModule', 'user', 'insertrss', [
'items' => $items,
'forum' => $forum]);
'items' => $items,
'forum' => $forum]);
if (!$insert) {
// something should happend here as well
}
}
}
14 changes: 7 additions & 7 deletions Container/HookContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ protected function setupHookBundles()
$this->registerHookSubscriberBundle($bundle3);
// Topic Provider Hooks
$bundle5 = new ProviderBundle('ZikulaDizkusModule', self::PROVIDER_UIAREANAME, 'ui_hooks', $this->__('Dizkus topic provider hook'));
$bundle5->addServiceHandler('display_view', 'Zikula\DizkusModule\HookHandlers', 'uiView', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('form_edit', 'Zikula\DizkusModule\HookHandlers', 'uiEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('form_delete', 'Zikula\DizkusModule\HookHandlers', 'uiDelete', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('validate_edit', 'Zikula\DizkusModule\HookHandlers', 'validateEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('validate_delete', 'Zikula\DizkusModule\HookHandlers', 'validateDelete', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('process_edit', 'Zikula\DizkusModule\HookHandlers', 'processEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('process_delete', 'Zikula\DizkusModule\HookHandlers', 'processDelete', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('display_view', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'uiView', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('form_edit', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'uiEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('form_delete', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'uiDelete', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('validate_edit', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'validateEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('validate_delete', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'validateDelete', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('process_edit', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'processEdit', 'dizkus.hooks.topic');
$bundle5->addServiceHandler('process_delete', 'Zikula\DizkusModule\HookHandler\TopicHookHandler', 'processDelete', 'dizkus.hooks.topic');
$this->registerHookProviderBundle($bundle5);
}
}
140 changes: 69 additions & 71 deletions Controller/AdminController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Dizkus
*
Expand Down Expand Up @@ -112,7 +111,7 @@ public function preferencesAction(Request $request)
}

return $this->render('@ZikulaDizkusModule/Admin/preferences.html.twig', [
'form' => $form->createView(),
'form' => $form->createView(),
]);
}

Expand Down Expand Up @@ -207,12 +206,12 @@ public function assignranksAction(Request $request)
throw new AccessDeniedException();
}

$page = (int)$request->query->get('page', 1);
$page = (int) $request->query->get('page', 1);
$letter = $request->query->get('letter');

if ($request->getMethod() == 'POST') {
$letter = $request->request->get('letter');
$page = (int)$request->request->get('page', 1);
$page = (int) $request->request->get('page', 1);

$setrank = $request->request->get('setrank');

Expand All @@ -226,15 +225,15 @@ public function assignranksAction(Request $request)
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$qb->select('u')
->from('Zikula\UsersModule\Entity\UserEntity', 'u')
->orderBy('u.uname', 'ASC');
->from('Zikula\UsersModule\Entity\UserEntity', 'u')
->orderBy('u.uname', 'ASC');
if ($letter != '*') {
$qb->andWhere('u.uname LIKE :letter')
->setParameter('letter', strtolower($letter) . '%');
->setParameter('letter', strtolower($letter) . '%');
}
$query = $qb->getQuery();
$query->setFirstResult(($page - 1) * $perpage)
->setMaxResults($perpage);
->setMaxResults($perpage);

// Paginator
$allusers = new Paginator($query);
Expand All @@ -256,13 +255,13 @@ public function assignranksAction(Request $request)
list($rankimages, $ranks) = $this->get('zikula_dizkus_module.rank_helper')->getAll(['ranktype' => RankEntity::TYPE_HONORARY]);

return $this->render('@ZikulaDizkusModule/Admin/assignranks.html.twig', [
'ranks' => $ranks,
'rankimages' => $rankimages,
'allusers' => $userArray,
'letter' => $letter,
'page' => $page,
'perpage' => $perpage,
'usercount' => $count
'ranks' => $ranks,
'rankimages' => $rankimages,
'allusers' => $userArray,
'letter' => $letter,
'page' => $page,
'perpage' => $perpage,
'usercount' => $count
]);
}

Expand All @@ -282,8 +281,8 @@ public function treeAction()
}

return $this->render('@ZikulaDizkusModule/Admin/tree.html.twig', [
'tree' => $this->getDoctrine()->getManager()->getRepository('Zikula\DizkusModule\Entity\ForumEntity')->childrenHierarchy(null, false)
]);
'tree' => $this->getDoctrine()->getManager()->getRepository('Zikula\DizkusModule\Entity\ForumEntity')->childrenHierarchy(null, false)
]);
}

/**
Expand Down Expand Up @@ -338,11 +337,11 @@ public function modifyForumAction(Request $request, $id = null)
}

return $this->render('@ZikulaDizkusModule/Admin/modifyforum.html.twig', [
'topiccount' => $topiccount,
'postcount' => $postcount,
'forum' => $forum,
'form' => $form->createView(),
]);
'topiccount' => $topiccount,
'postcount' => $postcount,
'forum' => $forum,
'form' => $form->createView(),
]);
}

/**
Expand All @@ -359,6 +358,7 @@ public function deleteforumAction(Request $request, $id = null)
if ($id) {
$forum = $this->getDoctrine()->getManager()->find('Zikula\DizkusModule\Entity\ForumEntity', $id);
if ($forum) {
//nothing to do here? @todo rearange this if
} else {
$this->addFlash('error', $this->__f('Forum with id %s not found', ['%s' => $id]), 403);

Expand All @@ -375,36 +375,36 @@ public function deleteforumAction(Request $request, $id = null)

// @todo move to form handler
$form = $this->createFormBuilder([])
->add('action', 'choice', [
'choices' => ['0' => $this->__('Remove them'),
'1' => $this->__('Move them to a new parent forum')],
'multiple' => false,
'expanded' => false,
'required' => true])
->add('destination', 'choice', [
'choices' => $destinations,
'choice_value' => function ($destination) {
//for some reason last element is null @FIXME
return $destination === null ? null : $destination->getForum_id();
},
'choice_label' => function ($destination) use ($forum) {
$isChild = $destination->getLft() > $forum->getLft() && $destination->getRgt() < $forum->getRgt() ? ' (' . $this->__("is child forum") . ')' : '';
$current = $destination->getForum_id() === $forum->getForum_id() ? ' (' . $this->__("current") . ')' : '';
$locked = $destination->isLocked() ? ' (' . $this->__("is locked") . ')' : '';

return str_repeat("--", $destination->getLvl()) . $destination->getName() . $current . $locked. $isChild;
},
'choice_attr' => function ($destination) use ($forum) {
$isChild = $destination->getLft() > $forum->getLft() && $destination->getRgt() < $forum->getRgt() ? true : false;

return $destination->getForum_id() === $forum->getForum_id() || $destination->isLocked() || $isChild ? ['disabled' => 'disabled'] : [];
},
'choices_as_values' => true,
'multiple' => false,
'expanded' => false,
'required' => true])
->add('remove', 'submit')
->getForm();
->add('action', 'choice', [
'choices' => ['0' => $this->__('Remove them'),
'1' => $this->__('Move them to a new parent forum')],
'multiple' => false,
'expanded' => false,
'required' => true])
->add('destination', 'choice', [
'choices' => $destinations,
'choice_value' => function ($destination) {
//for some reason last element is null @FIXME
return $destination === null ? null : $destination->getForum_id();
},
'choice_label' => function ($destination) use ($forum) {
$isChild = $destination->getLft() > $forum->getLft() && $destination->getRgt() < $forum->getRgt() ? ' (' . $this->__("is child forum") . ')' : '';
$current = $destination->getForum_id() === $forum->getForum_id() ? ' (' . $this->__("current") . ')' : '';
$locked = $destination->isLocked() ? ' (' . $this->__("is locked") . ')' : '';

return str_repeat("--", $destination->getLvl()) . $destination->getName() . $current . $locked . $isChild;
},
'choice_attr' => function ($destination) use ($forum) {
$isChild = $destination->getLft() > $forum->getLft() && $destination->getRgt() < $forum->getRgt() ? true : false;

return $destination->getForum_id() === $forum->getForum_id() || $destination->isLocked() || $isChild ? ['disabled' => 'disabled'] : [];
},
'choices_as_values' => true,
'multiple' => false,
'expanded' => false,
'required' => true])
->add('remove', 'submit')
->getForm();

$form->handleRequest($request);

Expand Down Expand Up @@ -450,9 +450,9 @@ public function deleteforumAction(Request $request, $id = null)
}

return $this->render('@ZikulaDizkusModule/Admin/deleteforum.html.twig', [
'forum' => $forum,
'form' => $form->createView(),
]);
'forum' => $forum,
'form' => $form->createView(),
]);
}

/**
Expand Down Expand Up @@ -496,11 +496,11 @@ public function manageSubscriptionsAction(Request $request, $uid = null)
}

return $this->render('@ZikulaDizkusModule/Admin/managesubscriptions.html.twig', [
'uid' => $uid,
'username' => $username,
'topicsubscriptions' => $topicsubscriptions,
'forumsubscriptions' => $forumsubscriptions
]);
'uid' => $uid,
'username' => $username,
'topicsubscriptions' => $topicsubscriptions,
'forumsubscriptions' => $forumsubscriptions
]);
}

/**
Expand All @@ -520,12 +520,10 @@ public function hookConfigAction($moduleName)

$hookconfig = $this->get('zikula_extensions_module.api.variable')->get($moduleName, 'dizkushookconfig');
// looks like module should always exist it would not be hooked
$module = $this->get('zikula_extensions_module.api.extension')->getModule($moduleName);
$moduleCapabilities = $module->getCapabilities();
// same hook_subscriber class should always exist right?
// maybe use CapabilityApi here ??
// $capabilities = $this->get('zikula_extensions_module.api.capability')->isCapable($moduleName, 'hook_subscriber');
$moduleHookContainerClass = $moduleCapabilities['hook_subscriber']['class'];
$module = $this->get('zikula_extensions_module.api.extension')->getModuleInstanceOrNull($moduleName);
$moduleHookCapable = $this->get('zikula_extensions_module.api.capability')->isCapable($moduleName, 'hook_subscriber');

$moduleHookContainerClass = $moduleHookCapable['class'];
$moduleHookContainer = new $moduleHookContainerClass($this->get('translator.default'));
$bindingsBetweenOwners = $this->get('hook_dispatcher')->getBindingsBetweenOwners($moduleName, $this->name);
foreach ($bindingsBetweenOwners as $k => $binding) {
Expand All @@ -535,11 +533,11 @@ public function hookConfigAction($moduleName)
}

return $this->render('@ZikulaDizkusModule/Hook/modifyconfig.html.twig', [
'areas' => $bindingsBetweenOwners,
'dizkushookconfig' => $hookconfig,
'activeModule' => $module,
'forums' => $this->get('zikula_dizkus_module.synchronization_helper')->getParents(null, true),
]);
'areas' => $bindingsBetweenOwners,
'dizkushookconfig' => $hookconfig,
'activeModule' => $module,
'forums' => $this->get('zikula_dizkus_module.forum_manager')->getParents(null, true),
]);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/ZikulaDizkusExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Dizkus.
*
Expand Down Expand Up @@ -27,7 +26,7 @@ class ZikulaDizkusExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(realpath(__DIR__.'/../Resources/config')));
$loader = new YamlFileLoader($container, new FileLocator(realpath(__DIR__ . '/../Resources/config')));

$loader->load('services.yml');
}
Expand Down
Loading