function wikiplugin_localfiles($data, $params) { // TODO refactor: defaults for plugins? $smartylib = TikiLib::lib('smarty'); $defaults = array(); $plugininfo = wikiplugin_localfiles_info(); foreach ($plugininfo['params'] as $key => $param) { $defaults[$key] = $param['default']; } $params = array_merge($defaults, $params); $files = array(); if (!is_array($params['path'])) { if ($params['list'] === 'y' && file_exists($params['path']) && is_dir($params['path'])) { $params['path'] = scandir(dir($params['path'])); } else { $params['path'] = array($params['path']); } } foreach ($params['path'] as $path) { $info = pathinfo($path); if (!$info || $info['basename'] === $path) { // windows file but non-windows server preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\\.([^\\.\\\\/]+?)|))[\\\\/\\.]*$%im', $path, $m); if (!empty($m[1])) { $info['dirname'] = $m[1]; } if (!empty($m[2])) { $info['basename'] = $m[2]; } if (!empty($m[5])) { $info['extension'] = $m[5]; } if (!empty($m[3])) { $info['filename'] = $m[3]; } // thanks http://www.php.net/manual/en/function.pathinfo.php#107461 } if ($params['icons'] === 'y') { $smartylib->loadPlugin('smarty_modifier_iconify'); $iconhtml = smarty_modifier_iconify($info['basename']); } $files[] = array('path' => $path, 'name' => $info['basename'], 'icon' => $iconhtml); } $smartylib->assign('files', $files); $smartylib->assign('isIE', strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false); return $smartylib->fetch('wiki-plugins/wikiplugin_localfiles.tpl'); }
function wikiplugin_attach($data, $params) { global $atts; global $mimeextensions; global $user, $section, $section_class; $wikilib = TikiLib::lib('wiki'); $tikilib = TikiLib::lib('tiki'); extract($params, EXTR_SKIP); $loop = array(); if (!isset($atts)) { $atts = array(); } if (!is_array($atts) || !array_key_exists("data", $atts) || count($atts["data"]) < 1) { // We're being called from a preview or something; try to build the atts ourselves. // See if we're being called from a tracker page. if ($section == 'trackers') { $trklib = TikiLib::lib('trk'); $atts_item_name = $_REQUEST["itemId"]; $tracker_info = $trklib->get_tracker($atts_item_name); $tracker_info = array_merge($tracker_info, $trklib->get_tracker_options($atts_item_name)); $attextra = 'n'; if (strstr($tracker_info["orderAttachments"], '|')) { $attextra = 'y'; } $attfields = explode(',', strtok($tracker_info["orderAttachments"], '|')); $atts = $trklib->list_item_attachments($atts_item_name, 0, -1, 'comment_asc', ''); } // See if we're being called from a wiki page. if (strstr($section_class, 'wiki_page')) { $atts_item_name = $_REQUEST["page"]; $atts = $wikilib->list_wiki_attachments($atts_item_name, 0, -1, 'created_desc', ''); } } // Save for restoration before this script ends $old_atts = $atts; $url = ''; if (isset($all) && intval($all) > 0) { $atts = $wikilib->list_all_attachements(0, -1, 'page_asc', ''); } elseif (!empty($page)) { if (!$tikilib->page_exists($page)) { return "''" . tr('Page "%0" does not exist', $page) . "''"; } if ($tikilib->user_has_perm_on_object($user, $page, 'wiki page', 'tiki_p_wiki_view_attachments') || $tikilib->user_has_perm_on_object($user, $_REQUEST['page'], 'wiki page', 'tiki_p_wiki_admin_attachments')) { $atts = $wikilib->list_wiki_attachments($page, 0, -1, 'created_desc', ''); $url = "&page={$page}"; } } if (!array_key_exists("cant", $atts)) { if (array_key_exists("data", $atts)) { $atts['cant'] = count($atts["data"]); } else { $atts['cant'] = 0; $atts["data"] = ""; } } if (!isset($num)) { $num = 0; } if (!isset($id)) { $id = 0; } else { $num = 0; } if (isset($file)) { $name = $file; } if (isset($name)) { $id = 0; $num = 0; } else { $name = ''; } if (!$atts['cant']) { return "''" . tra('No such attachment on this page') . "''"; } elseif ($num > 0 and $num < $atts['cant'] + 1) { $loop[] = $num; } else { $loop = range(1, $atts['cant']); } $out = array(); if ($data) { $out[] = $data; } foreach ($loop as $n) { $n--; if (!$name and !$id or $id == $atts['data'][$n]['attId'] or $name == $atts['data'][$n]['filename']) { $link = ""; if (isset($bullets) && $bullets) { $link .= "<li>"; } if (isset($image) and $image) { $link .= '<img src="tiki-download_wiki_attachment.php?attId=' . $atts['data'][$n]['attId'] . $url . '" class="wiki"'; $link .= ' alt="'; if (empty($showdesc) || empty($atts['data'][$n]['comment'])) { $link .= $atts['data'][$n]['filename']; } else { $link .= $atts['data'][$n]['comment']; } if (isset($dls)) { $link .= " " . $atts['data'][$n]['hits']; } $link .= '"/>'; } else { $link .= '<a href="tiki-download_wiki_attachment.php?attId=' . $atts['data'][$n]['attId'] . $url . '&download=y" class="wiki"'; $link .= ' title="'; if (empty($showdesc) || empty($atts['data'][$n]['comment'])) { $link .= $atts['data'][$n]['filename']; } else { $link .= $atts['data'][$n]['comment']; } if (isset($dls)) { $link .= " " . $atts['data'][$n]['hits']; } $link .= '">'; if (isset($icon)) { $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_modifier_iconify'); $iconhtml = smarty_modifier_iconify($atts['data'][$n]['filename']); $link .= $iconhtml . ' '; } if (!empty($showdesc) && !empty($atts['data'][$n]['comment'])) { $link .= strip_tags($atts['data'][$n]['comment']); } else { if (!empty($inline) && !empty($data)) { $link .= $data; } else { $link .= strip_tags($atts['data'][$n]['filename']); } } $link .= '</a>'; $pageall = strip_tags($atts['data'][$n]['page']); if (isset($all)) { $link .= " attached to " . '<a title="' . $pageall . '" href="' . $pageall . '" class="wiki">' . $pageall . '</a>'; } } if (isset($bullets) && $bullets) { $link .= "</li>"; } $out[] = $link; } } if (isset($bullets) && $bullets) { $separator = "\n"; } else { $separator = "<br />\n"; } if (!empty($inline) && !empty($data)) { if (array_key_exists(1, $out)) { $data = $out[1]; } else { $data = ""; } } else { $data = implode($separator, $out); } if (isset($bullets) && $bullets) { $data = "<ul>" . $data . "</ul>"; } if (strlen($data) == 0) { $data = "<strong>" . tra('No such attachment on this page') . "</strong>"; } $atts = $old_atts; return '~np~' . $data . '~/np~'; }