public function test_get_category_path() { $path = get_category_path(2); $this->assertEquals('/1/2', $path); $path = get_category_path(3); $this->assertEquals('/1/2/3', $path); $path = get_category_path(5); $this->assertEquals('/1/2/3/4/5', $path); }
function get_category_path($node) { global $wpdb; $parent = $wpdb->get_var("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_id={$node}"); $path = array(); if ($parent != 0) { $path[] = $parent; $path = array_merge(get_category_path($parent), $path); } return $path; }
} //----------------------------------------------------- //---Clickstream--------------------------------------- //----------------------------------------------------- $clickstream = "<span class=\"clickstream\"><a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\" class=\"clickstream\">" . $lang['home'] . "</a>" . $config['category_separator']; if ($mode == "lightbox" && $in_mode) { $page_url = ""; if (preg_match("/" . URL_PAGE . "=([0-9]+)/", $url, $regs)) { if (!empty($regs[1]) && $regs[1] != 1) { $page_url = "?" . URL_PAGE . "=" . $regs[1]; } } $clickstream .= "<a href=\"" . $site_sess->url(ROOT_PATH . "lightbox.php" . $page_url) . "\" class=\"clickstream\">" . $lang['lightbox'] . "</a>" . $config['category_separator']; } elseif ($mode == "search" && $in_mode) { $page_url = ""; if (preg_match("/" . URL_PAGE . "=([0-9]+)/", $url, $regs)) { if (!empty($regs[1]) && $regs[1] != 1) { $page_url = "&" . URL_PAGE . "=" . $regs[1]; } } $clickstream .= "<a href=\"" . $site_sess->url(ROOT_PATH . "search.php?show_result=1" . $page_url) . "\" class=\"clickstream\">" . $lang['search'] . "</a>" . $config['category_separator']; } else { $clickstream .= get_category_path($cat_id, 1) . $config['category_separator']; } $clickstream .= $image_name . "</span>"; //----------------------------------------------------- //--- Print Out --------------------------------------- //----------------------------------------------------- $site_template->register_vars(array("msg" => $msg, "clickstream" => $clickstream, "lang_category" => $lang['category'], "lang_added_by" => $lang['added_by'], "lang_description" => $lang['description'], "lang_keywords" => $lang['keywords'], "lang_date" => $lang['date'], "lang_hits" => $lang['hits'], "lang_downloads" => $lang['downloads'], "lang_rating" => $lang['rating'], "lang_votes" => $lang['votes'], "lang_author" => $lang['author'], "lang_comment" => $lang['comment'], "lang_prev_image" => $lang['prev_image'], "lang_next_image" => $lang['next_image'], "lang_file_size" => $lang['file_size'])); $site_template->print_template($site_template->parse_template($main_template)); include ROOT_PATH . 'includes/page_footer.php';
$font_face = un_htmlspecialchars(trim($HTTP_POST_VARS['font_face'])); $sender_name = un_htmlspecialchars(trim($HTTP_POST_VARS['sender_name'])); $sender_email = un_htmlspecialchars(trim($HTTP_POST_VARS['sender_email'])); $recipient_name = un_htmlspecialchars(trim($HTTP_POST_VARS['recipient_name'])); $recipient_email = un_htmlspecialchars(trim($HTTP_POST_VARS['recipient_email'])); $headline = un_htmlspecialchars(trim($HTTP_POST_VARS['headline'])); $message = un_htmlspecialchars(trim($HTTP_POST_VARS['message'])); $message = strip_tags($message); } $image = get_media_code($image_row['image_media_file'], $image_id, $cat_id, $image_row['image_name'], $mode, 1); $thumbnail = get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_id, $cat_id, $image_row['image_name'], $mode); $site_template->register_vars(array("image" => $image, "thumbnail" => $thumbnail, "image_name" => format_text($image_row['image_name']), "lang_bg_color" => $lang['bg_color'], "bg_color" => $bg_color, "lang_border_color" => $lang['border_color'], "border_color" => $border_color, "lang_font_color" => $lang['font_color'], "font_color" => $font_color, "lang_font_face" => $lang['font_face'], "font_face" => $font_face, "image_id" => $image_id, "lang_sender" => $lang['sender'], "lang_recipient" => $lang['recipient'], "lang_email" => $lang['email'], "lang_name" => $lang['name'], "lang_headline" => $lang['headline'], "lang_message" => $lang['message'], "lang_preview_postcard" => $lang['preview_postcard'], "url_postcard" => $site_sess->url(ROOT_PATH . "postcards.php?" . URL_IMAGE_ID . "=" . $image_id), "sender_name" => format_text(stripslashes($sender_name), 2), "sender_email" => format_text(stripslashes($sender_email), 2), "recipient_name" => format_text(stripslashes($recipient_name), 2), "recipient_email" => format_text(stripslashes($recipient_email), 2), "headline" => format_text(stripslashes($headline), 2), "message" => format_text(stripslashes($message), 2), "lang_send_postcard" => $lang['send_postcard'], "back_url" => format_text(stripslashes($url), 2))); } //----------------------------------------------------- //--- Clickstream ------------------------------------- //----------------------------------------------------- $clickstream = "<span class=\"clickstream\"><a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\" class=\"clickstream\">" . $lang['home'] . "</a>" . $config['category_separator']; if ($mode == "lightbox" && !empty($user_info['lightbox_image_ids'])) { $clickstream .= "<a href=\"" . $site_sess->url(ROOT_PATH . "lightbox.php") . "\" class=\"clickstream\">" . $lang['lightbox'] . "</a>" . $config['category_separator'] . "<a href=\"" . $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_id . "&mode=" . $mode) . "\" class=\"clickstream\">" . $image_row['image_name'] . "</a>" . $config['category_separator']; } elseif ($mode == "search" && !empty($session_info['search_id'])) { $clickstream .= "<a href=\"" . $site_sess->url(ROOT_PATH . "search.php?show_result=1") . "\" class=\"clickstream\">" . $lang['search'] . "</a>" . $config['category_separator'] . "<a href=\"" . $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_id . "&mode=" . $mode) . "\" class=\"clickstream\">" . $image_row['image_name'] . "</a>" . $config['category_separator']; } else { $clickstream .= get_category_path($cat_id, 1) . $config['category_separator'] . "<a href=\"" . $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_id) . "\" class=\"clickstream\">" . $image_row['image_name'] . "</a>" . $config['category_separator']; } $clickstream .= $lang['send_postcard'] . "</span>"; //----------------------------------------------------- //--- Print Out --------------------------------------- //----------------------------------------------------- $site_template->register_vars(array("msg" => $msg, "clickstream" => $clickstream)); $site_template->print_template($site_template->parse_template($main_template)); include ROOT_PATH . 'includes/page_footer.php';
if ($leftover > 0) { for ($i = 0; $i < $leftover; $i++) { $thumbnails .= "<td width=\"" . $imgtable_width . "\">\n \n</td>\n"; } $thumbnails .= "</tr>\n"; } } $thumbnails .= "</table>\n"; } //end else $site_template->register_vars("thumbnails", $thumbnails); unset($thumbnails); //----------------------------------------------------- //--- Clickstream ------------------------------------- //----------------------------------------------------- $clickstream = "<span class=\"clickstream\"><a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\" class=\"clickstream\">" . $lang['home'] . "</a>" . $config['category_separator'] . get_category_path($cat_id) . "</span>"; //----------------------------------------------------- //--- Print Out --------------------------------------- //----------------------------------------------------- $site_template->register_vars(array("msg" => $msg, "clickstream" => $clickstream)); $site_template->print_template($site_template->parse_template($main_template)); $content = ob_get_contents(); ob_end_clean(); if ($cache_page_categories) { // Reset session mode $site_sess->mode = $old_session_mode; save_cache_file($cache_id, $content); } } // end if get_cache_file() echo $content;
/** * Do the export * For most types this should not need to be overrided * @return boolean success */ function exportprocess() { global $CFG; // create a directory for the exports (if not already existing) if (!($export_dir = make_upload_directory($this->question_get_export_dir()))) { error(get_string('cannotcreatepath', 'quiz', $export_dir)); } $path = $CFG->dataroot . '/' . $this->question_get_export_dir(); // get the questions (from database) in this category // only get q's with no parents (no cloze subquestions specifically) $questions = get_questions_category($this->category, true); notify(get_string('exportingquestions', 'quiz')); $count = 0; // results are first written into string (and then to a file) // so create/initialize the string here $expout = ""; // track which category questions are in // if it changes we will record the category change in the output // file if selected. 0 means that it will get printed before the 1st question $trackcategory = 0; // iterate through questions foreach ($questions as $question) { // do not export hidden questions if (!empty($question->hidden)) { continue; } // do not export random questions if ($question->qtype == RANDOM) { continue; } // check if we need to record category change if ($this->cattofile) { if ($question->category != $trackcategory) { $trackcategory = $question->category; $categoryname = get_category_path($trackcategory); // create 'dummy' question for category export $dummyquestion = new object(); $dummyquestion->qtype = 'category'; $dummyquestion->category = $categoryname; $dummyquestion->name = "switch category to {$categoryname}"; $dummyquestion->id = 0; $dummyquestion->questiontextformat = ''; $expout .= $this->writequestion($dummyquestion) . "\n"; } } // export the question displaying message $count++; echo "<hr /><p><b>{$count}</b>. " . $this->format_question_text($question) . "</p>"; $expout .= $this->writequestion($question) . "\n"; } // continue path for following error checks $course = $this->course; $continuepath = "{$CFG->wwwroot}/question/export.php?courseid={$course->id}"; // did we actually process anything if ($count == 0) { print_error('noquestions', 'quiz', $continuepath); } // final pre-process on exported data $expout = $this->presave_process($expout); // write file $filepath = $path . "/" . $this->filename . $this->export_file_extension(); if (!($fh = fopen($filepath, "w"))) { print_error('cannotopen', 'quiz', $continuepath, $filepath); } if (!fwrite($fh, $expout, strlen($expout))) { print_error('cannotwrite', 'quiz', $continuepath, $filepath); } fclose($fh); return true; }
/** * Checks if there exists a record above that has the override flag set to true * @param $categoryid * @param $pluginname * @param $plugintype * @return bool true if locked, false if not locked * */ function is_plugin_overridden($categoryid, $pluginname, $plugintype) { global $DB; if (CONTEXTADMINDEBUG) { echo "is_plugin_locked({$categoryid},{$pluginname}, {$plugintype}):\n"; } if (empty($pluginname)) { return null; } $validplugins = array('modules', 'block'); // Valid types. if (!in_array($plugintype, $validplugins)) { debugging('Invalid plugintype passed to is_plugin_overridden in local/contextadmin/locallib.php', DEBUG_DEVELOPER); return null; } $path = get_category_path($categoryid); $pathstring = ltrim($path, '/'); $apath = explode('/', $pathstring); $arevpath = array_reverse($apath); // Remove the first element. We can't override ourselves. array_shift($arevpath); /* * go through the categories starting from nearest to top * 1. extract records for current category * 2. process records and collect up changes first in collection overrides later ones * 3. apply collected settings over the site_modules and return */ if (!empty($pluginname)) { foreach ($arevpath as $catid) { if ($DB->get_field("cat_" . $plugintype, 'override', array('name' => $pluginname, 'category_id' => $catid, 'override' => 1))) { return true; } } return false; } }