function get_parsed_template($templateId, $lang = null, $format = 'yaml') { $res = $this->get_template($templateId, $lang); if (!$res) { return false; } switch ($format) { case 'yaml': require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/installlib.php'; $content = "{CODE(caption=>YAML)}objects:\n" . " -\n" . " type: file_gallery\n" . " data:\n" . " " . implode("\n ", explode("\n", $res['content'])) . "{CODE}"; $profile = Tiki_Profile::fromString($content, $res['name']); $installer = new Tiki_Profile_Installer(); $objects = $profile->getObjects(); if (isset($objects[0])) { $data = $installer->getInstallHandler($objects[0])->getData(); unset($data['galleryId'], $data['parentId'], $data['name'], $data['user']); $res['content'] = $data; } else { $res['content'] = array(); } break; } return $res; }
protected function execute(InputInterface $input, OutputInterface $output) { $profileName = $input->getArgument('profile'); $repository = $input->getArgument('repository'); $force = $input->getOption('force'); $profile = \Tiki_Profile::fromNames($repository, $profileName); if (!$profile) { $output->writeln('<error>Profile not found.</error>'); return; } $tikilib = \TikiLib::lib('tiki'); $installer = new \Tiki_Profile_Installer(); $isInstalled = $installer->isInstalled($profile); if ($isInstalled && $force) { $installer->forget($profile); $isInstalled = false; } if (!$isInstalled) { $transaction = $tikilib->begin(); if ($installer->install($profile)) { $transaction->commit(); $output->writeln('Profile applied.'); } else { $output->writeln("<error>Installation failed:</error>"); foreach ($installer->getFeedback() as $error) { $output->writeln("<error>{$error}</error>"); } } } else { $output->writeln('<info>Profile was already applied. Nothing happened.</info>'); } }
function getData() { if ($this->data) { return $this->data; } $data = $this->obj->getData(); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function testGetObjects() { $builder = new Services_Workspace_ProfileBuilder(); $builder->addObject('wiki_page', 'foo', array('name' => 'Foo', 'namespace' => $builder->user('namespace'), 'content' => 'Hello', 'categories' => $builder->user('category'))); $builder->addObject('wiki_page', 'bar', array('name' => 'Bar', 'namespace' => $builder->user('namespace'), 'content' => 'World', 'categories' => $builder->user('category'))); $profile = Tiki_Profile::fromString($builder->getContent()); $analyser = new Services_Workspace_ProfileAnalyser($profile); $this->assertEquals(array(array('name' => 'Foo', 'namespace' => '{namespace}', 'content' => 'Hello'), array('name' => 'Bar', 'namespace' => '{namespace}', 'content' => 'World')), $analyser->getObjects('wiki_page')); }
function getData() { if ($this->data) { return $this->data; } $defaults = array('sections' => array('wiki'), 'type' => 'static'); $data = array_merge($defaults, $this->obj->getData()); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $defaults = array('description' => '', 'user' => 'admin', 'public' => 'n', 'max_posts' => 10, 'heading' => '', 'post_heading' => '', 'use_find' => 'y', 'comments' => 'n', 'show_avatar' => 'n'); $data = array_merge($defaults, $this->obj->getData()); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $defaults = array('title' => 'Title', 'private' => 'n', 'user' => '', 'geolocation' => ''); $data = array_merge($defaults, $this->obj->getData()); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
private function getData() { if ($this->data) { return $this->data; } $data = $this->obj->getData(); $data = Tiki_Profile::convertLists($data, array('show' => 'y', 'allow' => 'y'), true); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $defaults = array(); $data = array_merge($defaults, $this->obj->getData()); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $defaults = array('preferences' => array()); $data = array_merge($defaults, $this->obj->getData()); $data['preferences'] = Tiki_Profile::convertLists($data['preferences'], array('enable' => 'y', 'disable' => 'n')); $data['preferences'] = Tiki_Profile::convertYesNo($data['preferences']); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $defaults = array('cache' => 0, 'rows' => 10, 'custom' => null, 'groups' => array(), 'params' => array(), 'parse' => null); $data = array_merge($defaults, $this->obj->getData()); $data = Tiki_Profile::convertYesNo($data); $data['params'] = Tiki_Profile::convertYesNo($data['params']); return $this->data = $data; }
function getProfiles(array $channelNames) { $profiles = array(); foreach ($channelNames as $channelName) { $info = $this->channels[$channelName]; if ($profile = Tiki_Profile::fromNames($info['domain'], $info['profile'])) { $profiles[$channelName] = $profile; } } return $profiles; }
public static function serializeNamedObject($object) { if (strpos($object['domain'], '://') === false) { if (is_dir($object['domain'])) { $object['domain'] = "file://" . $object['domain']; } else { $object['domain'] = "http://" . $object['domain']; } } return sprintf("%s#%s", Tiki_Profile::getProfileKeyfor($object['domain'], $object['profile']), $object['object']); }
function getData() { if ($this->data) { return $this->data; } $data = $this->obj->getData(); $data = Tiki_Profile::convertLists($data, array('show' => 'y'), true); $defaults = array('description' => null, 'refresh' => 30, 'show_title' => 'n', 'show_publication_date' => 'n', 'article_generator' => null); $data = array_merge($defaults, $data); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
protected function execute(InputInterface $input, OutputInterface $output) { $addon_utilities = new \TikiAddons_Utilities(); $addonName = $input->getArgument('addon'); if (strpos($addonName, '/') !== false && strpos($addonName, '_') === false) { $package = $addonName; $folder = str_replace('/', '_', $addonName); } else { $package = str_replace('_', '/', $addonName); $folder = $addonName; } $repository = 'file://addons/' . $folder . '/profiles'; $reapply = $input->getOption('reapply'); $ignoredepends = $input->getOption('ignoredepends'); if (empty(glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml'))) { $output->writeln("<error>No profiles found.</error>"); return false; } if (!$ignoredepends) { $addon_utilities->checkDependencies($folder); } $addons = \TikiAddons::getInstalled(); $tikilib = \TikiLib::lib('tiki'); $installer = new \Tiki_Profile_Installer(); foreach (glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml') as $file) { $profileName = str_replace('.yml', '', basename($file)); $profile = \Tiki_Profile::fromNames($repository, $profileName); if (!$profile) { $output->writeln("<error>Profile {$profileName} not found.</error>"); continue; } $isInstalled = $installer->isInstalled($profile); if ($isInstalled && $reapply) { $installer->forget($profile); $isInstalled = false; } if (!$isInstalled) { $transaction = $tikilib->begin(); if ($installer->install($profile)) { $addon_utilities->updateProfile($folder, $addons[$package]->version, $profileName); $transaction->commit(); $output->writeln("Profile {$profileName} applied."); } else { $output->writeln("<error>Profile {$profileName} installation failed:</error>"); foreach ($installer->getFeedback() as $error) { $output->writeln("<error>{$error}</error>"); } } } else { $output->writeln("<info>Profile {$profileName} was already applied. Nothing happened.</info>"); } } }
function getData() { if ($this->data) { return $this->data; } $data = $this->obj->getData(); $defaults = array('description' => '', 'flood_interval' => 120, 'moderator' => 'admin', 'per_page' => 10, 'prune_max_age' => 3 * 24 * 3600, 'prune_unreplied_max_age' => 30 * 24 * 3600, 'topic_order' => 'lastPost_desc', 'thread_order' => '', 'section' => '', 'inbound_pop_server' => '', 'inbound_pop_port' => 110, 'inbound_pop_user' => '', 'inbound_pop_password' => '', 'outbound_address' => '', 'outbound_from' => '', 'approval_type' => 'all_posted', 'moderator_group' => '', 'forum_password' => '', 'attachments' => 'none', 'attachments_store' => 'db', 'attachments_store_dir' => '', 'attachments_max_size' => 10000000, 'forum_last_n' => 0, 'comments_per_page' => '', 'thread_style' => '', 'is_flat' => 'n', 'list_topic_reads' => 'n', 'list_topic_replies' => 'n', 'list_topic_points' => 'n', 'list_topic_last_post' => 'n', 'list_topic_last_post_title' => 'n', 'list_topic_last_post_avatar' => 'n', 'list_topic_author' => 'n', 'list_topic_author_avatar' => 'n', 'show_description' => 'n', 'enable_flood_control' => 'n', 'enable_inbound_mail' => 'n', 'enable_prune_unreplied' => 'n', 'enable_prune_old' => 'n', 'enable_vote_threads' => 'n', 'enable_outbound_for_inbound' => 'n', 'enable_outbound_reply_link' => 'n', 'enable_topic_smiley' => 'n', 'enable_topic_summary' => 'n', 'enable_ui_avatar' => 'n', 'enable_ui_rating_choice_topic' => 'n', 'enable_ui_flag' => 'n', 'enable_ui_posts' => 'n', 'enable_ui_level' => 'n', 'enable_ui_email' => 'n', 'enable_ui_online' => 'n', 'enable_password_protection' => 'n', 'forum_language' => ''); $data = Tiki_Profile::convertLists($data, array('enable' => 'y', 'list' => 'y', 'show' => 'y'), true); $data = array_merge($defaults, $data); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function getData() { if ($this->data) { return $this->data; } $data = $this->obj->getData(); $data = Tiki_Profile::convertLists($data, array('show' => 'y', 'allow' => 'y'), true); $defaults = array('show_pre_publication' => 'n', 'show_post_expire' => 'n', 'show_heading_only' => 'n', 'show_image' => 'n', 'show_avatar' => 'n', 'show_author' => 'n', 'show_publication_date' => 'n', 'show_expiration_date' => 'n', 'show_reads' => 'n', 'show_size' => 'n', 'show_topline' => 'n', 'show_subtitle' => 'n', 'show_link_to' => 'n', 'show_image_caption' => 'n', 'allow_ratings' => 'n', 'allow_comments' => 'n', 'allow_comments_rating_article' => 'n', 'allow_creator_edit' => 'n'); $data = array_merge($defaults, $data); $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function wikiplugin_profile( $data, $params ) { require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/installlib.php'; global $tiki_p_admin; if ( $tiki_p_admin != 'y' ) { return '__' . tra('Profile plugin only available to administrators') . '__'; } $params = array_merge(array('domain' => 'profiles.tiki.org'), $params); if ( !isset( $params['name'] ) ) { return 'Missing parameter __name__'; } $profile = Tiki_Profile::fromNames($params['domain'], $params['name']); if ( $profile ) { $installer = new Tiki_Profile_Installer; try { if ( $installer->isInstalled($profile) ) { if ( $_POST['reinstall'] == "{$params['domain']}/{$params['name']}" ) { $installer->forget($profile); $installer->install($profile); header('Location: ' . $_SERVER['REQUEST_URI']); exit; } } else { if ( $_POST['install'] == "{$params['domain']}/{$params['name']}" ) { $installer->install($profile); header('Location: ' . $_SERVER['REQUEST_URI']); exit; } } } catch( Exception $e ) { return '__' . $e->getMessage() . '__'; } global $smarty; $smarty->assign('profile_is_installed', $installer->isInstalled($profile)); $smarty->assign('profile_key', "{$params['domain']}/{$params['name']}"); return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_profile.tpl') . '~/np~'; } else { return '__' . tr('Profile %0/%1 not found', $params['domain'], $params['name']) . '__'; } }
function getData() { if ($this->data) { return $this->data; } $defaults = array('preserve' => 'n', 'guards' => array()); $data = array_merge($defaults, $this->obj->getData()); foreach ($data['guards'] as &$guard) { if (is_string($guard[2])) { $guard[2] = reset(Horde_Yaml::load("- " . $guard[2])); } } $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
function wikiplugin_datachannel($data, $params) { static $execution = 0; global $prefs, $smarty; $executionId = 'datachannel-exec-' . ++$execution; $fields = array(); $lines = explode("\n", $data); $lines = array_map('trim', $lines); $lines = array_filter($lines); foreach ($lines as $line) { $parts = explode(',', $line, 2); if (count($parts) == 2) { $fields[$parts[0]] = $parts[1]; } } require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/channellib.php'; require_once 'lib/profilelib/installlib.php'; $groups = Perms::get()->getGroups(); $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']); if ($config->canExecuteChannels(array($params['channel']), $groups)) { if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId) { $input = array_intersect_key($_POST, $fields); $static = $params; unset($static['channel']); $userInput = array_merge($input, $static); Tiki_Profile::useUnicityPrefix(uniqid()); $installer = new Tiki_Profile_Installer(); $installer->limitGlobalPreferences(array()); $profiles = $config->getProfiles(array($params['channel'])); $profile = reset($profiles); $installer->setUserData($userInput); $installer->install($profile); header('Location: ' . $_SERVER['REQUEST_URI']); } else { $smarty->assign('datachannel_fields', $fields); $smarty->assign('datachannel_execution', $executionId); return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~'; } } }
protected function execute(InputInterface $input, OutputInterface $output) { $profileName = $input->getArgument('profile'); $repository = $input->getArgument('repository'); $profile = \Tiki_Profile::fromNames($repository, $profileName); if (!$profile) { $output->writeln('<error>Profile not found.</error>'); return; } $tikilib = \TikiLib::lib('tiki'); $installer = new \Tiki_Profile_Installer(); $isInstalled = $installer->isInstalled($profile); if ($isInstalled) { $transaction = $tikilib->begin(); $installer->forget($profile); $transaction->commit(); $output->writeln('Profile forgotten.'); } else { $output->writeln('<info>Profile was not installed or did not create any objects.</info>'); } }
function forget(Tiki_Profile $profile) { $key = $profile->getProfileKey(); unset($this->installed[$key]); $profile->removeSymbols(); }
include_once 'lib/core/Zend/Log/Writer/Syslog.php'; $log_level = Zend_Log::INFO; $writer = new Zend_Log_Writer_Stream('php://output'); $writer->addFilter((int) $log_level); $logger = new Zend_Log($writer); $logger->debug('Running search shell utility'); require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/installlib.php'; if ($_SERVER['argv'][1] === 'install') { $args = $_SERVER['argv']; $script = array_shift($args); $command = array_shift($args); $profile = array_shift($args); $repository = array_shift($args); if (!$repository) { $repository = 'profiles.tiki.org'; } if (!$profile) { $logger->err('Profile not specified.'); exit(1); } $profile = Tiki_Profile::fromNames($repository, $profile); if (!$profile) { $logger->err('Profile not found'); exit(1); } $transaction = $tikilib->begin(); $installer = new Tiki_Profile_Installer(); $installer->install($profile); $transaction->commit(); }
function action_edit_template($input) { if (!Perms::get()->admin) { throw new Services_Exception_Denied(); } global $prefs; $template = $this->utilities->getTemplate($input->id->int()); if ($template['is_advanced'] == 'y') { return array('FORWARD' => array('action' => 'advanced_edit', 'id' => $input->id->int())); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $builder = new Services_Workspace_ProfileBuilder(); if ($prefs['feature_areas'] == 'y' && $input->area->int()) { $builder->addObject('area_binding', 'binding', array('category' => $builder->user('category'), 'perspective' => $builder->user('perspective'))); } foreach ($input->groups as $internal => $info) { $permissions = array_filter(preg_split('/\\W+/', $info->permissions->none())); $builder->addGroup($internal, $info->name->text(), $info->autojoin->int() > 0); $builder->setPermissions($internal, 'category', $builder->user('category'), $permissions); } $builder->setManagingGroup($input->managingGroup->word()); foreach ($input->pages as $page) { $builder->addObject('wiki_page', uniqid(), array('name' => $page->name->pagename(), 'namespace' => $page->namespace->pagename(), 'content' => $page->content->wikicontent(), 'categories' => $builder->user('category'))); } $this->utilities->replaceTemplate($input->id->int(), array('name' => $input->name->text(), 'definition' => $builder->getContent())); } $template = $this->utilities->getTemplate($input->id->int()); $profile = Tiki_Profile::fromString($template['definition']); $analyser = new Services_Workspace_ProfileAnalyser($profile); $hasArea = $analyser->contains(array('type' => 'area_binding', 'ref' => 'binding', 'category' => $analyser->user('category'), 'perspective' => $analyser->user('perspective'))) ? 'y' : 'n'; return array('title' => tr('Edit template %0', $template['name']), 'id' => $input->id->int(), 'name' => $template['name'], 'area' => $prefs['feature_areas'] == 'y' ? $hasArea : null, 'groups' => $analyser->getGroups('category', $analyser->user('category')), 'pages' => $analyser->getObjects('wiki_page', array('name' => '{namespace}', 'namespace' => null, 'content' => ''))); }
protected function execute(InputInterface $input, OutputInterface $output) { $addon_utilities = new \TikiAddons_Utilities(); $addonName = $input->getArgument('addon'); if (strpos($addonName, '/') !== false && strpos($addonName, '_') === false) { $package = $addonName; $folder = str_replace('/', '_', $addonName); } else { $package = str_replace('_', '/', $addonName); $folder = $addonName; } $repository = 'file://addons/' . $folder . '/profiles'; $ignoredepends = $input->getOption('ignoredepends'); $confirm = $input->getOption('confirm'); if (empty(glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml'))) { $output->writeln("<error>No profiles found.</error>"); return; } if (!$ignoredepends) { $addon_utilities->checkDependencies($folder); } $upgradeInfo = json_decode(file_get_contents(TIKI_PATH . '/addons/' . $folder . '/upgrade.json')); $validVersions = array(); foreach ($upgradeInfo as $version => $info) { $validVersions[] = $version; } $config = null; $lastVersionInstalled = $addon_utilities->getLastVersionInstalled($folder); $reapplyProfiles = array(); $forgetProfiles = array(); $removeItems = array(); foreach ($validVersions as $v) { if ($addon_utilities->checkVersionMatch($lastVersionInstalled, $v)) { $config = $upgradeInfo->{$v}; $removeItems = $config->remove; $forgetProfiles = $config->forget; $reapplyProfiles = $config->reapply; break; } } $addons = \TikiAddons::getInstalled(); if (!$config) { if (strnatcmp($lastVersionInstalled, $addons[$package]->version) <= 0) { $output->writeln("<error>Currently installed version ({$lastVersionInstalled}) is already up to date.</error>"); } else { $output->writeln("<error>No valid versions currently installed to upgrade found.</error>"); } return false; } $installedProfiles = $addon_utilities->getInstalledProfiles($folder); $installedProfileNames = array_keys($installedProfiles); $willRemove = false; foreach ($removeItems as $remove) { if (empty($remove->profile)) { $profile = ''; } else { $profile = $remove->profile; } $objectId = $addon_utilities->getObjectId($folder, $remove->ref, $profile); $objectType = $remove->type; if ($objectId) { if ($confirm) { $addon_utilities->removeObject($objectId, $objectType); $output->writeln("{$objectType} '{$objectId}' has been deleted."); } else { $output->writeln("<info>{$objectType} '{$objectId}' will be deleted.</info>"); } $willRemove = true; } } $tikilib = \TikiLib::lib('tiki'); $installer = new \Tiki_Profile_Installer(); // First forget profiles that need to be forgotten foreach ($forgetProfiles as $toForget) { if (in_array($toForget, $installedProfileNames)) { if ($confirm || !$willRemove) { $addon_utilities->forgetProfileAllVersions($folder, $toForget); $profile = \Tiki_Profile::fromNames($repository, $toForget); if (!$profile) { $output->writeln("<error>Profile {$toForget} not found.</error>"); } else { $installer->forget($profile); } } else { $output->writeln("<info>The installed profile {$toForget} will be forgotten.</info>"); } } } if (!$confirm && $willRemove) { $output->writeln("<error>There will be NO undo, and all data in the above objects will be deleted as part of the upgrade.</error>"); $output->writeln("<info>Use the --confirm option to proceed with removal and upgrade.</info>"); } if ($confirm || !$willRemove) { // Finally install profiles foreach (glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml') as $file) { $profileName = str_replace('.yml', '', basename($file)); $profile = \Tiki_Profile::fromNames($repository, $profileName); if (in_array($profileName, $reapplyProfiles)) { $reapply = true; } else { $reapply = false; } if (!$profile) { $output->writeln("<error>Profile {$profileName} not found.</error>"); continue; } $isInstalled = $installer->isInstalled($profile); if ($isInstalled && $reapply) { $installer->forget($profile); $isInstalled = false; } if (!$isInstalled) { $transaction = $tikilib->begin(); if ($installer->install($profile)) { $addon_utilities->updateProfile($folder, $addons[$package]->version, $profileName); $transaction->commit(); $output->writeln("Profile {$profileName} applied."); } else { $output->writeln("<error>Profile {$profileName} installation failed:</error>"); foreach ($installer->getFeedback() as $error) { $output->writeln("<error>{$error}</error>"); } } } else { $output->writeln("<info>Profile {$profileName} was already applied. Nothing happened.</info>"); } } } }
} if ( ! $config->canExecuteChannels($channels, $groups) ) { $access->display_error( 'tiki-channel.php', tra('One of the requested channels cannot be requested. It does not exist or permission is denied.') ); } $profiles = $config->getProfiles($channels); if ( count($profiles) != count($channels) ) { $access->display_error('tiki-channel.php', tra('One of the install profiles could not be obtained.')); } Tiki_Profile::useUnicityPrefix(uniqid()); $installer = new Tiki_Profile_Installer; $installer->limitGlobalPreferences(array()); foreach ( $calls as $call ) { list($channel, $userInput) = $call; // Profile can be installed multiple times // Only last values preserved $profile = $profiles[$channel]; $installer->forget($profile); $installer->setUserData($userInput); $installer->install($profile); }
/** * @param $filename * @return array|mixed */ private function read_module_file($filename) { $cachelib = TikiLib::lib('cache'); $expiry = filemtime($filename); if ($modules = $cachelib->getSerialized($filename, 'modules', $expiry)) { return $modules; } $content = file_get_contents($filename); if (!$content) { TikiLib::lib('errorreport')->report(tr('Module file "%0" not found.', $filename)); return ''; } $profile = Tiki_Profile::fromString("{CODE(caption=>YAML)}{$content}{CODE}"); $out = array_fill_keys(array_values($this->module_zones), array()); foreach ($profile->getObjects() as $object) { if ($object->getType() == 'module') { $handler = new Tiki_Profile_InstallHandler_Module($object, array()); $data = $handler->getData(); $object->replaceReferences($data); $data = $handler->formatData($data); $data['groups'] = unserialize($data['groups']); $position = $data['position']; $zone = $this->module_zones[$position]; $out[$zone][] = $data; } } $cachelib->cacheItem($filename, serialize($out), 'modules'); return $out; }
function wikiplugin_datachannel($data, $params) { static $execution = 0; global $prefs, $smarty, $headerlib; $executionId = 'datachannel-exec-' . ++$execution; if (isset($params['price']) && $params['price'] == 0) { // Convert things like 0.00 to empty unset($params['price']); } $fields = array(); $inputfields = array(); $lines = explode("\n", $data); $lines = array_map('trim', $lines); $lines = array_filter($lines); $js = ''; if (!isset($params['array_values'])) { $params['array_values'] = 'n'; } foreach ($lines as $line) { $parts = explode(',', $line, 2); $parts = array_map('trim', $parts); if (count($parts) == 2) { if (strpos($parts[1], 'external') === 0) { // e.g. "fieldid,external=fieldname" $moreparts = explode('=', $parts[1], 2); $moreparts = array_map('trim', $moreparts); if (count($moreparts) < 2) { $moreparts[1] = $parts[0]; // no fieldname supplied so use same as fieldid } $fields[$parts[0]] = $moreparts[0]; if ($params['array_values'] === 'y' && preg_match('/[\\[\\]\\.#\\=]/', $moreparts[1])) { // check for [ ] = or . which would be a jQuery selector // might select multiple inputs $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("' . $moreparts[1] . '").serialize()));'; } else { // otherwise it's an id $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("#' . $moreparts[1] . '").val()));'; } $inputfields[$parts[0]] = 'external'; } elseif (strpos($parts[1], 'hidden') === 0) { $moreparts = explode('=', $parts[1], 2); $moreparts = array_map('trim', $moreparts); $fields[$parts[0]] = $moreparts[1]; $inputfields[$parts[0]] = 'hidden'; } else { $fields[$parts[0]] = $parts[1]; $inputfields[$parts[0]] = $parts[1]; } } } $groups = Perms::get()->getGroups(); $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']); if ($config->canExecuteChannels(array($params['channel']), $groups, true)) { $smarty->assign('datachannel_execution', $executionId); if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId && $config->canExecuteChannels(array($params['channel']), $groups)) { $input = array_intersect_key(array_map('trim', $_POST), $inputfields); $itemIds = array(); // process possible arrays in post if ($params['array_values'] === 'y') { foreach ($input as $key => $val) { if (!empty($val)) { parse_str($val, $vals); if (is_array($vals)) { // serialized collection of inputs $arr = array(); if ($key == 'itemId') { foreach ($vals as $v) { // itemId[x,y,z] if (is_array($v)) { $arr = array_merge($arr, $v); } } $itemIds = $arr; } else { foreach ($vals as $v) { // fieldname[x=>a,y=>b,z=>c] if (is_array($v)) { foreach ($v as $k => $kv) { if (in_array($k, $itemIds)) { // check if sent in itemIds array $arr[] = $kv; // (e.g. from trackerlist checkboxes) } } } else { $arr = $val; // not an array, so use the initial string val } } } $input[$key] = $arr; } } } } $inputs = array(); if ($params['array_values'] === 'y' && !empty($itemIds)) { $cid = count($itemIds); for ($i = 0; $i < $cid; $i++) { // reorganise array $arr = array(); foreach (array_keys($input) as $k) { if (isset($input[$k]) && is_array($input[$k])) { $arr[$k] = $input[$k][$i]; } else { $arr[$k] = $input[$k]; } } $inputs[] = $arr; } } else { $inputs[] = $input; } $static = $params; $unsets = wikiplugin_datachannel_info(); // get defined params $unsets = array_keys($unsets['params']); foreach ($unsets as $un) { // remove defined params leaving user supplied ones unset($static[$un]); } if (!empty($params['price'])) { global $paymentlib; require_once 'lib/payment/paymentlib.php'; $desc = empty($params['paymentlabel']) ? tr('Datachannel:', $prefs['site_language']) . ' ' . $params['channel'] : $params['paymentlabel']; $posts = array(); foreach ($input as $key => $post) { $posts[$key] = $post; $desc .= '/' . $post; } $id = $paymentlib->request_payment($desc, $params['price'], $prefs['payment_default_delay']); $paymentlib->register_behavior($id, 'complete', 'execute_datachannel', array($data, $params, $posts, $executionId)); require_once 'lib/smarty_tiki/function.payment.php'; return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^'; } foreach ($inputs as $input) { $userInput = array_merge($input, $static); Tiki_Profile::useUnicityPrefix(uniqid()); $profiles = $config->getProfiles(array($params['channel'])); $profile = reset($profiles); $profile->removeSymbols(); Tiki_Profile::useUnicityPrefix(uniqid()); $installer = new Tiki_Profile_Installer(); //TODO: What is the following line for? Future feature to limit capabilities of data channels? //$installer->limitGlobalPreferences( array() ); // jb tiki6: looks like if set to an empty array it would prevent any prefs being set // i guess the idea is to be able to restrict the settable prefs to only harmless ones for security $installer->setUserData($userInput); if (!empty($params['debug']) && $params['debug'] === 'y') { $installer->setDebug(); } $params['emptyCache'] = isset($params['emptyCache']) ? $params['emptyCache'] : 'all'; $installer->install($profile, $params['emptyCache']); } if (empty($params['returnURI'])) { $params['returnURI'] = $_SERVER['HTTP_REFERER']; } // default to return to same page if (empty($params['debug']) || $params['debug'] != 'y') { if (isset($params['quietReturn']) && $params['quietReturn'] == 'y') { return true; } else { header('Location: ' . $params['returnURI']); } die; } $smarty->assign('datachannel_feedbacks', array_merge($installer->getFeedback(), $profile->getFeedback())); } $smarty->assign('datachannel_inputfields', $inputfields); $smarty->assign('datachannel_fields', $fields); $smarty->assign('button_label', !empty($params['buttonLabel']) ? $params['buttonLabel'] : 'Go'); $smarty->assign('form_class_attr', !empty($params['class']) ? ' class="' . $params['class'] . '"' : ''); if (!empty($js)) { $headerlib->add_js("function datachannel_form_submit{$execution}() {{$js}\nreturn true;\n}"); $smarty->assign('datachannel_form_onsubmit', ' onsubmit="return datachannel_form_submit' . $execution . '();"'); } else { $smarty->assign('datachannel_form_onsubmit', ''); } return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~'; } }
function getData() { if ($this->data) { return $this->data; } $defaults = array('owner' => 'admin', 'public' => 'n', 'galleryId' => null, 'parent' => -1, 'visible' => 'n'); $conversions = array('owner' => 'user', 'max_rows' => 'maxRows', 'parent' => 'parentId'); $columns = array('id', 'icon', 'name', 'size', 'description', 'created', 'hits', 'lastDownload', 'lockedby', 'modified', 'author', 'last_user', 'comment', 'files', 'backlinks', 'deleteAfter', 'checked', 'share', 'source', 'explorer', 'path', 'slideshow'); $data = $this->obj->getData(); $data = Tiki_Profile::convertLists($data, array('flags' => 'y')); $column = isset($data['column']) ? $data['column'] : array(); $popup = isset($data['popup']) ? $data['popup'] : array(); if (in_array('name', $column) && in_array('filename', $column)) { $data['show_name'] = 'a'; unset($column[array_search('name', $column)], $column[array_search('filename', $column)]); unset($columns[array_search('name', $columns)]); } else { if (in_array('name', $column)) { $data['show_name'] = 'n'; unset($column[array_search('name', $column)]); unset($columns[array_search('name', $columns)]); } else { if (in_array('filename', $column)) { $data['show_name'] = 'f'; unset($column[array_search('filename', $column)]); unset($columns[array_search('name', $columns)]); } } } $both = array_intersect($column, $popup); if ($column || $popup) { $hide = array_diff($columns, array_merge($column, $popup)); } else { $hide = array(); // use defaults if nothing set } $column = array_diff($column, $both); $popup = array_diff($popup, $both); foreach ($both as $value) { $data["show_{$value}"] = 'a'; } foreach ($column as $value) { $data["show_{$value}"] = 'y'; } foreach ($popup as $value) { $data["show_{$value}"] = 'o'; } foreach ($hide as $value) { $data["show_{$value}"] = 'n'; } unset($data['popup']); unset($data['column']); $data = array_merge($defaults, $data); foreach ($conversions as $old => $new) { if (array_key_exists($old, $data)) { $data[$new] = $data[$old]; unset($data[$old]); } } unset($data['galleryId']); $this->replaceReferences($data); if (!empty($data['name'])) { global $filegallib; require_once 'lib/filegals/filegallib.php'; $data['galleryId'] = $filegallib->getGalleryId($data['name'], $data['parentId']); } return $this->data = $data; }
public static function serializeNamedObject($object) { return sprintf("%s#%s", Tiki_Profile::getProfileKeyfor($object['domain'], $object['profile']), $object['object']); }