예제 #1
0
function reg_user($user)
{
    global $Cfg, $Paths, $Current_weblog;
    $name_md5 = strtolower(md5(strtolower($user['name'])));
    if (save_serialize($Paths['pivot_path'] . 'db/users/' . $name_md5 . '.php', $user)) {
        printf("<h2>%s</h2>\n\n", lang('commentuser', 'user_stored'));
    } else {
        printf("<h2>%s</h2>\n\n", lang('commentuser', 'user_stored_failed'));
    }
    $self = $Paths['host'] . $_SERVER['PHP_SELF'];
    $mail1 = lang('commentuser', 'registered') . "\n\n";
    $mail2 = lang('commentuser', 'reg_verify_long') . "\n\n";
    $url = sprintf("%s?func=verify&name=%s&code=%s&w=%s", $self, urlencode($user['name']), md5($user['pass'] . "email"), para_weblog($Current_weblog));
    $mail = sprintf($mail1 . $mail2, $Cfg['sitename'], $url);
    if (!mail($user['email'], "[Pivot] " . lang('commentuser', 'reg_confirmation'), $mail, "From: " . $user['email'])) {
        $mail2 = '<a href="%s">' . lang('commentuser', 'reg_verify_short') . '</a>';
        $mail = sprintf($mail1 . $mail2, $Cfg['sitename'], $url);
        echo "\n<br />" . nl2br($mail) . "<br />\n";
    } else {
        echo sprintf(lang('commentuser', 'reg_verification'), $user['email']);
    }
    notify_new('visitor_registration', array('add', $user['name']));
}
예제 #2
0
/**
 * Make a link to an entry, using the settings for how they should be formed.
 *
 * @param mixed $data
 * @param string $weblog
 * @param string $anchor
 * @param string $parameter
 * @param boolean $para_weblog
 */
function make_filelink($data = "", $weblog = "", $anchor = "comm", $parameter = "", $para_weblog = false)
{
    global $db, $Weblogs, $Current_weblog, $Cfg, $Paths;
    // Set the weblog, if it isn't set already.
    if ($weblog == "") {
        $weblog = $Current_weblog;
    }
    // Set the 'log_url' path, if it isn't set already.
    if (empty($Paths['log_url'])) {
        $Paths['log_url'] = dirname(get_log_url('index')) . "/";
        if ($Paths['log_url'] == "//") {
            $Paths['log_url'] = "/";
        }
    }
    // Set $entry (and $code)
    if (empty($data)) {
        // Using current entry - the db object must exist and be set
        $entry = $db->entry;
        $code = $entry['code'];
    } elseif (is_array($data)) {
        // Using passed/inputed entry
        $entry = $data;
        $code = $entry['code'];
    } elseif (is_numeric($data)) {
        $code = $data;
        // Using the entry with the given $code
        // If it's not the current one, we need to load it
        if (!isset($db) || $code != $db->entry['code']) {
            $fl_db = new db(FALSE);
            $fl_db->read_entry($code);
            $entry = $fl_db->entry;
        } else {
            $entry = $db->entry;
        }
    } else {
        debug('Entry code must be an integer/numeric - no output.');
        return;
    }
    if (!$Weblogs[$weblog]['live_entries']) {
        $filelink = $Paths['pivot_url'] . $Weblogs[$weblog]['entry_path'] . $Weblogs[$weblog]['entry_filename'];
    } else {
        if (isset($Cfg['mod_rewrite']) && $Cfg['mod_rewrite'] != 0 && $entry['date'] != "") {
            // if $entry['date'] is not set, we cant make the non-crufty url,
            // and we fall back to the crufty one..
            switch ($Cfg['mod_rewrite']) {
                // archive/2005/04/20/title_of_entry
                case "1":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    list($yr, $mo, $da, $ho, $mi) = split("-", $entry['date']);
                    $filelink = $Paths['log_url'] . "/archive/{$yr}/{$mo}/{$da}/" . $name;
                    // Reverted it to original, since suggested fix breaks htaccess mod rewrite
                    // $filelink = $Paths['log_url'] . $Weblogs[$weblog]['archive_path'] . "/$yr/$mo/$da/".$name;
                    break;
                    // archive/2005-04-20/title_of_entry
                // archive/2005-04-20/title_of_entry
                case "2":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    list($yr, $mo, $da, $ho, $mi) = split("-", $entry['date']);
                    $filelink = $Paths['log_url'] . "/archive/{$yr}-{$mo}-{$da}/" . $name;
                    // Reverted it to original, since suggested fix breaks htaccess mod rewrite
                    // $filelink = $Paths['log_url'] . $Weblogs[$weblog]['archive_path'] . "/$yr-$mo-$da/".$name;
                    break;
                    // entry/1234
                // entry/1234
                case "3":
                    $filelink = $Paths['log_url'] . "/entry/" . $code;
                    break;
                    // entry/1234/title_of_entry
                // entry/1234/title_of_entry
                case "4":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    $filelink = $Paths['log_url'] . "/entry/" . $code . "/{$name}";
                    break;
            }
        } else {
            $filelink = $Paths['pivot_url'] . "entry.php?id=%1{$parameter}";
        }
    }
    // Add a weblog parameter if asked for, or if multiple weblogs, and the current weblog is not the first one..
    if ($para_weblog || para_weblog_needed($weblog)) {
        if (!$Weblogs[$weblog]['live_entries']) {
            $filelink .= "?w=" . para_weblog($weblog);
        } else {
            if (strpos($filelink, "?") > 0) {
                // if there's already a '?' in the link, we add the parameter using &amp;w=
                $filelink .= "&amp;w=" . para_weblog($weblog);
            } else {
                // else we treat it as an extra 'folder'
                $filelink .= "/" . para_weblog($weblog);
            }
        }
    }
    $filelink = fixPath($filelink);
    $filelink = str_replace("%1", $code, $filelink);
    $filelink = format_date("", $filelink, $entry['title']);
    if ($anchor != "") {
        $filelink .= "#" . $anchor;
    }
    return $filelink;
}
예제 #3
0
/**
 * Make a link to any given $tag.
 *
 * @param string $tag
 * @param string $template
 * @return string
 */
function tagLink($tag, $template = "")
{
    global $Paths, $Current_weblog, $Cfg;
    $tag = normalizeTag($tag);
    if ($Cfg['mod_rewrite'] == 0 && $Cfg['mod_taglinks'] != 1) {
        $link = $Paths['pivot_url'] . "tags.php?tag=" . urlencode($tag);
        if (para_weblog_needed($Current_weblog)) {
            $link .= "&amp;w=" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "&amp;t={$template}";
        }
        return $link;
    } else {
        if ($Cfg['mod_rewrite'] == 0) {
            $link = $Paths['pivot_url'] . "tags.php";
            if (para_weblog_needed($Current_weblog)) {
                $link .= "?w=" . para_weblog($Current_weblog);
                if ($template != "") {
                    $link .= "&amp;t={$template}";
                }
            } else {
                if ($template != "") {
                    $link .= "?t={$template}";
                }
            }
            return $link . "/" . urlencode($tag);
        } else {
            $link = $Paths['log_url'] . "tag";
            if (para_weblog_needed($Current_weblog)) {
                $link .= "/w=" . para_weblog($Current_weblog);
            }
            if ($template != "") {
                $link .= "/t={$template}";
            }
            return $link . "/" . urlencode($tag);
        }
    }
}
예제 #4
0
    } else {
        $Pivot_Vars['t'] = "";
    }
} else {
    $Pivot_Vars['t'] = basename($Pivot_Vars['t']);
}
// If non-crufty URLs (mod_rewrite) is enabled and someone tries to
// access the crufty URL, redirect. (Search engine friendly.)
list($request_script) = explode("?", $_SERVER['REQUEST_URI']);
if ($Cfg['mod_rewrite'] && basename($request_script) == "archive.php" && $Pivot_Vars['c'] != "") {
    $Current_weblog = $Pivot_Vars['w'];
    set_paths_log_url();
    $filelink = $Paths['log_url'] . "category/" . $Pivot_Vars['c'];
    // Handle addition query parameters
    if (para_weblog_needed($Pivot_Vars['w'])) {
        $query = '?w=' . para_weblog($Pivot_Vars['w']) . '&';
    } else {
        $query = '?';
    }
    unset($_GET['c']);
    unset($_GET['w']);
    foreach ($_GET as $key => $value) {
        $query .= $key . '=' . urlencode($value) . '&';
    }
    if ($query != '?') {
        $filelink .= substr($query, 0, -1);
    }
    // Redirect
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: {$filelink}");
    exit;
예제 #5
0
/**
 * Make a link to any given $tag.
 *
 * @param string $tag
 * @param string $template
 * @return string
 */
function tagLink($tag, $template = "")
{
    global $PIVOTX;
    $Current_weblog = $PIVOTX['weblogs']->getCurrent();
    $tag = normalizeTag($tag);
    $site_url = getDefault($PIVOTX['weblogs']->get($Current_weblog, 'site_url'), $PIVOTX['paths']['site_url']);
    if ($PIVOTX['config']->get('mod_rewrite') == 0) {
        $link = $site_url . "?t=" . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "&amp;w=" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "&amp;t={$template}";
        }
    } else {
        $prefix = getDefault($PIVOTX['config']->get('localised_tag_prefix'), 'tag');
        $link = $site_url . makeURI($prefix) . '/' . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "/" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "/?t={$template}";
        }
    }
    // Check if there's a hook set, and if so call it.
    if ($PIVOTX['extensions'] && $PIVOTX['extensions']->hasHook('make_link#tag')) {
        $PIVOTX['extensions']->executeHook('make_link#tag', $link, array('tag' => $tag, 'w' => $Current_weblog));
    }
    return $link;
}
예제 #6
0
 function doit($action, $text, $cats, $amountperpage, $params)
 {
     global $PIVOTX;
     $Current_weblog = $PIVOTX['weblogs']->getCurrent();
     $modifier = $PIVOTX['parser']->get('modifier');
     // $amountperpage must be numeric, one or larger
     if (!is_numeric($amountperpage) || $amountperpage < 1) {
         return "<!-- snippet {$this->name} error: invalid number of entries to skip ({$amountperpage}) -->\n";
     }
     // Preserving some query parameters
     $query = array();
     if (isset($_GET['w']) && (empty($_GET['rewrite']) || $_GET['rewrite'] == 'offset')) {
         $query['w'] = 'w=' . $_GET['w'];
     }
     if (isset($_GET['t'])) {
         $query['t'] = 't=' . $_GET['t'];
     }
     if (!empty($_GET['u'])) {
         $query['u'] = 'u=' . $_GET['u'];
     }
     // Setting the text for the links
     if ($action == "next") {
         $text = getDefault($params['format'], __("Next page") . " &#187;");
     } elseif ($action == "prev") {
         $text = getDefault($params['format'], "&#171; " . __("Previous page"));
     } elseif ($action == "digg") {
         $text_prev = getDefault($params['format_prev'], "&#171; " . __("Previous page"));
         $text_next = getDefault($params['format_next'], __("Next page") . " &#187;");
     } else {
         $text = getDefault($params['format'], __("Displaying entries %num_from%-%num_to% of %num_tot%"));
     }
     // Get the maximum amount of pages to show.
     $max_digg_pages = getDefault($params['maxpages'], 9);
     // Get the id to attach to the <ul> for Digg style navigation.
     $digg_id = getDefault($params['id'], "pages");
     // Start the real work.
     $eachcatshash = md5(implodeDeep("", $cats));
     if ($PIVOTX['cache']->get('paging', $eachcatshash)) {
         // Check if this is in our simple cache?
         list($temp_tot, $num_tot) = $PIVOTX['cache']->get('paging', $eachcatshash);
     } else {
         // Get the total amount of entries. How we do this depends on the used DB-model..
         // What we do is we get the amount of entries for each item in $cats.
         // For example, let's say we have 10 entries per page and 90 entries in one subweblog, and
         // 65 in the other. In this case we don't need (90+65)/10 pages, but (max(90,65))/10 pages.
         if ($PIVOTX['db']->db_type == "flat") {
             // Get the amount from the Flat files DB..
             $tot = $PIVOTX['db']->get_entries_count();
             foreach ($cats as $eachcats) {
                 if (!is_array($eachcats) && trim($eachcats) == '') {
                     continue;
                 }
                 $temp_tot = count($PIVOTX['db']->read_entries(array('show' => $tot, 'cats' => $eachcats, 'user' => $_GET['u'], 'status' => 'publish')));
                 $num_tot = max($num_tot, $temp_tot);
             }
         } else {
             // Get the amount from our SQL db..
             // Set up DB factory
             $sqlFactory = new sqlFactory($PIVOTX['config']->get('db_model'), $PIVOTX['config']->get('db_databasename'), $PIVOTX['config']->get('db_hostname'), $PIVOTX['config']->get('db_username'), $PIVOTX['config']->get('db_password'));
             // Set up DB connection
             $sql = $sqlFactory->getSqlInstance();
             $entriestable = safeString($PIVOTX['config']->get('db_prefix') . "entries", true);
             $categoriestable = safeString($PIVOTX['config']->get('db_prefix') . "categories", true);
             foreach ($cats as $eachcats) {
                 if (is_array($eachcats)) {
                     $eachcats = implode("','", $eachcats);
                 } else {
                     if (trim($eachcats) == '') {
                         continue;
                     }
                 }
                 $qry['select'] = "COUNT(DISTINCT(e.uid))";
                 $qry['from'] = $entriestable . " AS e, " . $categoriestable . " as c";
                 $qry['where'][] = "e.status='publish' AND e.uid=c.target_uid AND c.category IN ('{$eachcats}')";
                 $sqlquery = $sql->build_select($qry);
                 $sql->query($sqlquery);
                 $temp_tot = current($sql->fetch_row());
                 $num_tot = max($num_tot, $temp_tot);
             }
         }
         $PIVOTX['cache']->set('paging', $eachcatshash, array($temp_tot, $num_tot));
     }
     $offset = intval($modifier['offset']);
     $num_pages = ceil($num_tot / $amountperpage);
     if ($num_tot == 0) {
         return "<!-- snippet {$this->name}: no entries -->\n";
     } elseif ($offset >= $num_pages) {
         return "<!-- snippet {$this->name}: no more entries -->\n";
     }
     if ($action == "next") {
         $offset++;
         if ($offset >= $num_pages) {
             return "<!-- snippet {$this->name} (next): no more entries -->\n";
         }
     } elseif ($action == "prev") {
         if ($offset == 0) {
             return "<!-- snippet {$this->name} (previous): no previous entries -->\n";
         } else {
             $offset--;
         }
     } else {
         if ($num_tot == 0) {
             return "<!-- snippet {$this->name} (curr): no current entries -->\n";
         } else {
             $num = min($num, $num_tot);
         }
     }
     $num_from = $offset * $amountperpage + 1;
     $num_to = min($num_tot, ($offset + 1) * $amountperpage);
     $text = str_replace("%num%", min($num_tot, $amountperpage), $text);
     $text = str_replace("%num_tot%", $num_tot, $text);
     $text = str_replace("%num_from%", $num_from, $text);
     $text = str_replace("%num_to%", $num_to, $text);
     if ($action == "curr") {
         return $text;
     }
     $site_url = getDefault($PIVOTX['weblogs']->get($Current_weblog, 'site_url'), $PIVOTX['paths']['site_url']);
     if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
         // Ensure that we get a sorted list of unique categories in
         // the URL - better SEO, one unique URL.
         $catslink = implodeDeep(",", $cats);
         $catslink = array_unique(explode(",", $catslink));
         sort($catslink, SORT_STRING);
         $catslink = implode(",", $catslink);
     }
     if ($PIVOTX['config']->get('mod_rewrite') == 0) {
         if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
             $link = $site_url . "?c=" . $catslink . "&amp;o=";
         } else {
             $link = $site_url . "?o=";
         }
     } else {
         if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
             $categoryname = getDefault($PIVOTX['config']->get('localised_category_prefix'), "category");
             $link = $site_url . $categoryname . "/" . $catslink . "/";
         } else {
             $pagesname = getDefault($PIVOTX['config']->get('localised_browse_prefix'), "browse");
             $link = $site_url . $pagesname . "/";
         }
     }
     if ($action == 'digg') {
         $link .= '%offset%';
     } else {
         $link .= $offset;
     }
     if (!isset($query['w']) && paraWeblogNeeded($Current_weblog)) {
         if ($PIVOTX['config']->get('mod_rewrite') == 0) {
             $link .= "&amp;w=" . para_weblog($Current_weblog);
         } else {
             $link .= "/" . para_weblog($Current_weblog);
         }
     }
     // Add the query parameters (if any)
     if (count($query) > 0) {
         $query = implode('&amp;', $query);
         if ($PIVOTX['config']->get('mod_rewrite') == 0) {
             $link .= '&amp;' . $query;
         } else {
             $link .= '?' . $query;
         }
     }
     $link = str_replace(array('"', "'"), "", $link);
     if ($action != 'digg') {
         // Perhaps add some extra attributes to the <a> tag
         $extra = "";
         if (!empty($params['target'])) {
             $extra .= " target='" . $params['target'] . "'";
         }
         if (!empty($params['class'])) {
             $extra .= " class='" . $params['class'] . "'";
         }
         if (!empty($params['id'])) {
             $extra .= " id='" . $params['id'] . "'";
         }
         if (!empty($params['datarole'])) {
             $extra .= " data-role='" . $params['datarole'] . "'";
         }
         $output = sprintf('<a href="%s" %s>%s</a>', $link, $extra, $text);
         return $output;
     } else {
         $output = "\n<div id=\"{$digg_id}\">\n    <ul>\n    %links%\n    </ul>\n</div>";
         $links = '';
         // Adding the previous link
         if ($offset == 0) {
             $links .= '<li class="nolink">%text_prev%</li>';
         } else {
             $links .= '<li><a href="%url%">%text_prev%</a></li>';
             $url = str_replace('%offset%', max(0, $offset - 1), $link);
             $links = str_replace('%url%', $url, $links);
         }
         if ($num_pages > $max_digg_pages) {
             // Limit the number of links/listed pages.
             $max_digg_pages = intval($max_digg_pages);
             $start = (int) ($offset - 0.5 * ($max_digg_pages - 1));
             $start = max(0, $start) + 1;
             $stop = (int) ($offset + 0.5 * ($max_digg_pages - 1));
             $stop = max(min(1000, $stop), 3);
             $page = $offset;
             if ($offset == 0) {
                 $links .= '<li class="current">1</li>';
             } else {
                 if ($start >= 1) {
                     $links .= '<li><a href="%url%">1</a></li>';
                     if ($start >= 2) {
                         $links .= '<li class="skip">&#8230;</li>';
                     }
                     $url = str_replace('%offset%', 0, $link);
                     $links = str_replace('%url%', $url, $links);
                 }
             }
         } else {
             // Display all links/listed pages.
             $start = 0;
             $stop = 100;
         }
         // Adding all links before the current page
         while ($start < $offset) {
             $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
             $url = str_replace('%offset%', $start, $link);
             $links = str_replace('%url%', $url, $links);
             $start++;
         }
         // Current page..
         if ($start == $offset) {
             $links .= '<li class="current">' . ($start + 1) . '</li>';
             $start++;
         }
         // Adding all links after the current page
         while ($start < $num_pages) {
             if ($start < $stop) {
                 $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
                 $url = str_replace('%offset%', $start, $link);
                 $links = str_replace('%url%', $url, $links);
             } else {
                 if ($start == $num_pages - 2) {
                     $links .= '<li class="skip">&#8230;</li>';
                 } else {
                     if ($start == $num_pages - 1) {
                         $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
                         $url = str_replace('%offset%', $start, $link);
                         $links = str_replace('%url%', $url, $links);
                     }
                 }
             }
             $page++;
             $start++;
         }
         // Adding the next link
         if ($offset + 1 >= $num_pages) {
             $links .= '<li class="nolink">%text_next%</li>';
         } else {
             $links .= '<li><a href="%url%">%text_next%</a></li>';
             $url = str_replace('%offset%', $offset + 1, $link);
             $links = str_replace('%url%', $url, $links);
         }
         $output = str_replace('%links%', $links, $output);
         $output = str_replace('%text_prev%', $text_prev, $output);
         $output = str_replace('%text_next%', $text_next, $output);
         return $output;
     }
 }
예제 #7
0
/**
 * Display a small tagcloud.
 *
 * @param integer $amount
 * @param integer $minsize
 * @param integer $maxsize
 * @param string $template
 * @return string
 */
function snippet_tagcloud($amount = 0, $minsize = 0, $maxsize = 0, $template = "")
{
    global $Paths, $Current_weblog, $Cfg;
    if ($minsize == 0) {
        $minsize = 8;
    }
    if ($maxsize == 0) {
        $maxsize = 17;
    }
    if ($amount == 0) {
        $amount = 20;
    }
    $tagcosmos = getTagCosmos($amount, $Current_weblog);
    // This is the factor we need to calculate the EM sizes. $minsize is 1 em,
    // $maxsize will be ($maxsize / $minsize) EM.. Take care if $tagcosmos['maxvalue'] == $tagcosmos['minvalue']
    if ($tagcosmos['maxvalue'] != $tagcosmos['minvalue']) {
        $factor = ($maxsize - $minsize) / ($tagcosmos['maxvalue'] - $tagcosmos['minvalue']) / $minsize;
    } else {
        $factor = 0;
    }
    foreach ($tagcosmos['tags'] as $key => $value) {
        // Calculate the size, depending on value.
        $nSize = sprintf("%0.2f", 1 + ($value - $tagcosmos['minvalue']) * $factor);
        $htmllinks[$key] = sprintf("<a style=\"font-size:%sem;\" href=\"%s\"\r\n\t\t  rel=\"tag\" title=\"%s: %s, %s %s\">%s</a>\n", $nSize, tagLink($key, $template), lang('tags', 'tag'), $key, $value, lang('userbar', 'entries'), $key);
    }
    $output = "<div id='tagcloud' style='font-size: {$minsize}px;'>";
    $output .= implode(" ", $htmllinks);
    if (para_weblog_needed($Current_weblog)) {
        $para .= "?w=" . para_weblog($Current_weblog);
        $para .= $template != "" ? "&amp;t={$template}" : "";
    } else {
        $para = $template != "" ? "?t={$template}" : "";
    }
    if ($Cfg['mod_rewrite'] == 0) {
        $link = $Paths['pivot_url'] . "tags.php";
    } else {
        $link = $Paths['log_url'] . "tags";
    }
    $output .= sprintf('<em>(<a href="%s%s">%s</a>)</em>', $link, $para, lang('general', 'all'));
    $output .= "</div>";
    return $output;
}
예제 #8
0
/**
 * Make a link to an entry, using the settings for how they should be formed.
 *
 * @param mixed $data
 * @param string $weblog
 * @param string $anchor
 * @param string $parameter
 * @param boolean $para_weblog
 */
function makeFilelink($data = "", $weblog = "", $anchor = "comm", $parameter = "", $para_weblog = false)
{
    global $PIVOTX;
    // Set the weblog, if it isn't set already.
    if ($weblog == "") {
        $weblog = $PIVOTX['weblogs']->getCurrent();
    }
    // Set $entry (and $code)
    if (empty($data)) {
        // Using current entry - the db object must exist and be set
        $template_vars = $PIVOTX['template']->get_template_vars();
        $uid = $template_vars['uid'];
    } elseif (is_array($data)) {
        // Using passed/inputed entry
        $entry = $data;
        $uid = $entry['uid'];
    } elseif (is_numeric($data)) {
        $uid = $data;
        // Using the entry with the given $code
        // If it's not the current one, we need to load it
        if (!isset($PIVOTX['db']) || $uid != $PIVOTX['db']->entry['uid']) {
            $fl_db = new db(FALSE);
            $fl_db->read_entry($uid);
            $entry = $fl_db->entry;
        } else {
            $entry = $PIVOTX['db']->entry;
        }
    } else {
        debug('Entry code must be an integer/numeric - no output.');
        return;
    }
    $site_url = getDefault($PIVOTX['weblogs']->get($weblog, 'site_url'), $PIVOTX['paths']['site_url']);
    $site_url = addTrailingSlash($site_url);
    switch ($PIVOTX['config']->get('mod_rewrite')) {
        // Mod rewrite disabled..
        case "0":
        case "":
            $filelink = sprintf("%s?e=%s%s", $site_url, $uid, $parameter);
            break;
            // archive/2005/04/20/title_of_entry
        // archive/2005/04/20/title_of_entry
        case "1":
            $name = $entry['uri'];
            $archiveprefix = makeURI(getDefault($PIVOTX['config']->get('localised_archive_prefix'), "archive"));
            list($yr, $mo, $da, $ho, $mi) = preg_split("/[ :-]/", $entry['date']);
            $filelink = $site_url . "{$archiveprefix}/{$yr}/{$mo}/{$da}/{$name}";
            break;
            // archive/2005-04-20/title_of_entry
        // archive/2005-04-20/title_of_entry
        case "2":
            $name = $entry['uri'];
            $archiveprefix = makeURI(getDefault($PIVOTX['config']->get('localised_archive_prefix'), "archive"));
            list($yr, $mo, $da, $ho, $mi) = preg_split("/[ :-]/", $entry['date']);
            $filelink = $site_url . "{$archiveprefix}/{$yr}-{$mo}-{$da}/{$name}";
            break;
            // entry/1234
        // entry/1234
        case "3":
            $entryprefix = makeURI(getDefault($PIVOTX['config']->get('localised_entry_prefix'), "entry"));
            $filelink = $site_url . "{$entryprefix}/{$uid}";
            break;
            // entry/1234/title_of_entry
        // entry/1234/title_of_entry
        case "4":
            $name = $entry['uri'];
            $entryprefix = makeURI(getDefault($PIVOTX['config']->get('localised_entry_prefix'), "entry"));
            $filelink = $site_url . "{$entryprefix}/{$uid}/{$name}";
            break;
            // 2005/04/20/title_of_entry
        // 2005/04/20/title_of_entry
        case "5":
            $name = $entry['uri'];
            list($yr, $mo, $da, $ho, $mi) = preg_split("/[ :-]/", $entry['date']);
            $filelink = $site_url . "{$yr}/{$mo}/{$da}/{$name}";
            break;
            // 2005-04-20/title_of_entry
        // 2005-04-20/title_of_entry
        case "6":
            $name = $entry['uri'];
            list($yr, $mo, $da, $ho, $mi) = preg_split("/[ :-]/", $entry['date']);
            $filelink = $site_url . "{$yr}-{$mo}-{$da}/{$name}";
            break;
    }
    // Add a weblog parameter if asked for, or if multiple weblogs
    if ($para_weblog || paraWeblogNeeded($weblog)) {
        if ($PIVOTX['config']->get('mod_rewrite')) {
            // we treat it as an extra 'folder'
            $filelink .= "/" . para_weblog($weblog);
        } else {
            $filelink .= "&amp;w=" . para_weblog($weblog);
        }
    }
    $filelink = fixPath($filelink);
    $filelink = str_replace("%1", $code, $filelink);
    $filelink = formatDate("", $filelink, $entry['title']);
    if ($anchor != "") {
        $filelink .= "#" . $anchor;
    }
    // Check if there's a hook set, and if so call it. This hook has no 'return' value.
    if ($PIVOTX['extensions'] && $PIVOTX['extensions']->hasHook('make_link#entries')) {
        $PIVOTX['extensions']->executeHook('make_link#entries', $filelink, array('uri' => $entry['uri'], 'title' => $entry['title'], 'uid' => $entry['uid'], 'date' => $entry['date'], 'w' => $weblog));
    }
    return $filelink;
}
예제 #9
0
/**
 * Sends notification for any type - currently only entries/comments.
 *
 * @param string $type
 * @param array $data
 * @return void
 */
function notify_new($type, $data)
{
    global $Paths, $Current_weblog, $Users, $Weblogs, $i18n_use;
    // FIXME:
    // $contact_addr used below is not set because there is really no
    // good setting for that - the comment_emailto setting for each e-mail
    // isn't meant for the from header...
    if ($type == 'comment') {
        // splitting up input data
        $entry = $data[0];
        $comment = $data[1];
        if (isset($data[2]) && $data[2]) {
            debug("Notification of new comment surpressed.");
            return;
        }
        // make a nice title for the mail..
        if (strlen($entry['title']) > 2) {
            $title = $entry['title'];
            $title = strip_tags($title);
        } else {
            $title = substr($entry['introduction'], 0, 300);
            $title = strip_tags($title);
            $title = str_replace("\n", "", $title);
            $title = str_replace("\r", "", $title);
            $title = substr($title, 0, 60);
        }
        $id = safe_string($comment["name"], TRUE) . "-" . format_date($comment["date"], "%ye%%month%%day%%hour24%%minute%");
        // Make the array of users that want to be notified via email..
        $notify_arr = array();
        foreach ($entry['comments'] as $temp_comm) {
            if ($temp_comm['notify'] == 1 && isemail($temp_comm['email'])) {
                $notify_arr[$temp_comm['email']] = 1;
            }
            if ($temp_comm['notify'] == 0 && isemail($temp_comm['email'])) {
                unset($notify_arr[$temp_comm['email']]);
            }
        }
        // don't send to the user that did the comment...
        if (isset($notify_arr[$comment['email']])) {
            unset($notify_arr[$comment['email']]);
        }
        // send mail to those on the 'notify me' list..
        if (count($notify_arr) > 0) {
            $contact_addr = $Users[$entry['user']]['email'];
            $user = $Users[$entry['user']]['nick'];
            if (empty($user)) {
                $user = $entry['user'];
            }
            if (!$i18n_use) {
                $user = utf8_encode($user);
            }
            $body = sprintf(lang('comment', 'email_posted_comm') . ":\n\n", unentify($comment['name']));
            $body .= sprintf("%s", unentify($comment['comment']));
            $body .= sprintf("\n\n-------------\n");
            $body .= sprintf(lang('weblog_text', 'name') . ": %s\n", unentify($comment['name']));
            $body .= sprintf(lang('comment', 'email_comm_on') . "\n", $title);
            $body .= sprintf("\n%s:\n%s%s\n", lang('comment', 'email_view_entry'), $Paths['host'], make_filelink($entry['code'], "", ""));
            $body .= sprintf("%s:\n%s%s\n", lang('comment', 'email_view_comm'), $Paths['host'], make_filelink($entry['code'], "", $id));
            if (!$i18n_use) {
                $body = utf8_encode($body);
            }
            $body = decode_text($body, 'special');
            $contact_name = '=?UTF-8?B?' . base64_encode($user) . '?=';
            $add_header = sprintf("From: \"'%s'\" <%s>\n", $contact_name, $contact_addr);
            $add_header .= "MIME-Version: 1.0\n";
            $add_header .= "Content-Type: text/plain; charset=UTF-8; format=flowed\n";
            $add_header .= "Content-Transfer-Encoding: 8bit\n";
            $subject = lang('comment', 'email_subject_notify') . " Re: {$title}";
            if (!$i18n_use) {
                $subject = utf8_encode($subject);
            }
            $subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
            foreach ($notify_arr as $addr => $val) {
                $addr = trim($addr);
                @mail($addr, $subject, $body, $add_header);
                debug("Sent Notify to {$addr} from '" . $comment['name'] . "'");
            }
        }
    } else {
        if ($type == 'entry') {
            $entry = $data;
            // We need to determine the current weblog..
            $weblogs = find_weblogs_with_cat($entry['category']);
            $Current_weblog = current($weblogs);
            // make a nice title for the mail..
            if (strlen($entry['title']) > 2) {
                $title = $entry['title'];
                $title = strip_tags($title);
            } else {
                $title = substr($entry['introduction'], 0, 300);
                $title = strip_tags($title);
                $title = str_replace("\n", "", $title);
                $title = str_replace("\r", "", $title);
                $title = substr($title, 0, 60);
            }
            $title = unentify($title);
            // Make the array of users that want to be notified via email..
            $comment_users = get_registered_visitors();
            $notify_arr = array();
            foreach ($comment_users as $commuserdata) {
                if ($commuserdata['verified'] && !$commuserdata['disabled'] && $commuserdata['notify_entries']) {
                    $notify_arr[$commuserdata['email']] = $commuserdata['name'];
                }
            }
            // send mail to those on the 'notify me' list..
            if (count($notify_arr) > 0) {
                $contact_addr = $Users[$entry['user']]['email'];
                // Get the user's nickname (or username if nickname
                // isn't set), and the weblog's name.
                $user = $Users[$entry['user']]['nick'];
                if (empty($user)) {
                    $user = $entry['user'];
                }
                if (!$i18n_use) {
                    $user = utf8_encode($user);
                }
                $weblog = find_weblogs_with_cat($entry['category']);
                $weblog = $Weblogs[$weblog[0]]['name'];
                $defaultbody = sprintf(lang('comment', 'email_posted_entry') . ":\n\n", $user);
                $defaultbody .= sprintf("%s\n\n%s\n", $title, unentify(strip_tags($entry['introduction'])));
                $defaultbody .= sprintf("\n\n-------------\n");
                $defaultbody .= sprintf("\n%s:\n%s%s\n", lang('comment', 'email_view_fullentry'), $Paths['host'], make_filelink($entry, "", ""));
                $defaultbody .= sprintf("\n%s:\n%s%suser.php%s\n", lang('comment', 'email_view_settings'), $Paths['host'], $Paths['pivot_url'], "?w=" . para_weblog($Current_weblog));
                $defaultbody .= sprintf("\n%s: %%name%% (%%addr%%)\n", lang('comment', 'email_sent_to'), $Paths['host'], $Paths['pivot_url']);
                $defaultbody = decode_text($defaultbody, 'special');
                if (!$i18n_use) {
                    $defaultbody = utf8_encode($defaultbody);
                }
                $contact_name = '=?UTF-8?B?' . base64_encode($user) . '?=';
                $add_header = sprintf("From: \"'%s'\" <%s>\n", $contact_name, $contact_addr);
                $add_header .= "MIME-Version: 1.0\n";
                $add_header .= "Content-Type: text/plain; charset=UTF-8; format=flowed\n";
                $add_header .= "Content-Transfer-Encoding: 8bit\n";
                $subject = lang('comment', 'email_subject_notify') . " {$title} - {$weblog}";
                if (!$i18n_use) {
                    $subject = utf8_encode($subject);
                }
                $subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
                $notified = array();
                foreach ($notify_arr as $addr => $name) {
                    $addr = trim($addr);
                    $body = $defaultbody;
                    $body = str_replace("%name%", $name, $body);
                    $body = str_replace("%addr%", $addr, $body);
                    @mail($addr, $subject, $body, $add_header);
                    debug("Sent Notify to {$addr} from '" . $entry['user'] . "'");
                    $notified[] = sprintf("%s (%s)", $name, $addr);
                }
                $notified = sprintf("%s: %s", lang('comment', 'email_notified'), implode(", ", $notified));
                return $notified;
            }
        } else {
            if ($type == 'visitor_registration') {
                $type = $data[0];
                $name = $data[1];
                // Only sending notification to superadmin
                foreach ($Users as $key => $value) {
                    if ($value['userlevel'] == 4) {
                        $user = $key;
                        break;
                    }
                }
                $contact_addr = $Users[$user]['email'];
                $contact_name = $Users[$user]['nick'];
                if (empty($contact_name)) {
                    $contact_name = $user;
                }
                if ($type == 'add') {
                    $subject = "New visitor registration - {$name}";
                } else {
                    $subject = "New visitor confirmed - {$name}";
                }
                $body = $subject;
                $body .= sprintf("\n\nView visitor information:\n%s%s?menu=admin&func=admin&do=seecommusers\n", $Paths['host'], $Paths['pivot_url']);
                if (!$i18n_use) {
                    $contact_name = utf8_encode($contact_name);
                    $subject = utf8_encode($subject);
                    $body = utf8_encode($body);
                }
                $contact_name = '=?UTF-8?B?' . base64_encode($contact_name) . '?=';
                $add_header = sprintf("From: \"'%s'\" <%s>\n", $contact_name, $contact_addr);
                $add_header .= "MIME-Version: 1.0\n";
                $add_header .= "Content-Type: text/plain; charset=UTF-8; format=flowed\n";
                $add_header .= "Content-Transfer-Encoding: 8bit\n";
                $subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
                @mail($contact_addr, $subject, $body, $add_header);
                debug("Sent registered visitor notification for {$name}");
                return;
            } else {
                debug("Unknown notify type '{$type}'");
            }
        }
    }
}