Example #1
0
/**
 * Generates the forms used to do create nav's
 * @param int $bid Widget id number
 * @return string Markup
 */
function _nav_edit_table($bid)
{
    global $ssc_database;
    $result = $ssc_database->query("SELECT n.id, n.title, n.description, n.url, COUNT(n.id) lvl FROM\n\t\t\t\t\t\t\t#__navigation n, #__navigation p WHERE n.l BETWEEN p.l AND p.r\n\t\t\t\t\t\t\tAND p.bid = %d AND n.bid = %d GROUP BY n.id ORDER BY n.l", $bid, $bid);
    if (!$result || $ssc_database->number_rows() == 0) {
        //blank
        return '';
    }
    $items = array();
    // Store the "parent" dropdown
    $parent = array(0);
    // Item->parent relationship temp storage
    $p = -1;
    $struct = array();
    // Store menu widget hierarchy
    $ptr =& $struct;
    // Pointer to structure
    $id = -1;
    $prev = array();
    // Pointers to previous hierarchy nodes
    $lvl = 1;
    // Current level
    while ($data = $ssc_database->fetch_object($result)) {
        if ($data->lvl > $lvl) {
            // Taking a step IN
            $prev[$lvl] =& $ptr;
            $ptr =& $ptr[$id];
            $lvl++;
            $parent[$data->lvl] = $data->id;
            // Save current parent
            $p = $parent[$lvl - 1];
        } else {
            if ($data->lvl < $lvl) {
                do {
                    // Step back
                    $ptr =& $prev[--$lvl];
                } while ($data->lvl < $lvl);
                $parent[$lvl] = $data->id;
                $p = $parent[$lvl - 1];
            } else {
                $parent[$data->lvl] = $data->id;
                // Save current parent
            }
        }
        // (Now?) Within the same level
        $id = $data->id;
        if ($lvl == 1) {
            $p = $id;
            $parent[1] = $id;
        }
        $data->pid = $p;
        $ptr[$id]['#data'] = $data;
        $items[$id] = $data->title;
    }
    // Now to parse this link structure
    $struct['#items'] = $items;
    $out = '<form action="" method="post"><table class="admin-table center-input"><tr><th>ID</th><th>Parent</th><th>Title</th><th>Description</th><th>Path</th></tr>';
    $out .= _nav_edit_table_parser($struct, true);
    $out .= '</table><div><input type="hidden" name="form-id" value="_nav_edit_table" />' . theme_render_input(array('#type' => 'submit', '#value' => 'Save', '#name' => 'sub')) . '</div></form>';
    return $out;
}
Example #2
0
/**
 * Render a checkbox
 * @param array $structure Element structure
 * @return string XHTML construction
 */
function theme_render_checkbox($structure)
{
    $out = '<div class="form-item form-checkbox"><label ' . (isset($structure['#id']) ? 'for="' . $structure['#id'] . '"' : '') . '>';
    $out .= theme_render_input($structure) . $structure['#title'] . '</label>';
    if (!empty($structure['#description'])) {
        $out .= '<div class="form-desc">' . $structure['#description'] . '</div>';
    }
    $out .= '</div>';
    return $out;
}
Example #3
0
/**
 * Implementation of module_content()
 * 
 * Blog content and parameters can be interpreted in several different methods
 * 
 *   - /
 *     No parameters.  Should show (paged) all posts in the blog.
 * 
 *   - /tag/xxx 
 *     Responds with paged posts relating to that tag.
 * 
 *   - /yyyy/mm/dd/post-name
 *     Retrieve the post based on the url safe-name
 * 
 *   - /id/123
 *     Used as permalink.  Perma-redirect to current /yyyy/mm/dd/post-name url
 * 
 *   - /yyyy
 *     Archival retrieval of posts (no content) in the specified year
 *     
 *   - /atom
 *     Atom style feed for the current blog
 */
function blog_content()
{
    global $ssc_database, $ssc_site_path;
    $result = $ssc_database->query("SELECT name, comments, page FROM #__blog WHERE id = %d LIMIT 1", $_GET['path-id']);
    if ($result && ($data = $ssc_database->fetch_assoc($result))) {
        // Load display library
        if (!ssc_load_library('sscText')) {
            ssc_not_found();
            return;
        }
        // Get blog settings
        ssc_set_title($data['name']);
        $_GET['param'] = explode("/", $_GET['param']);
        $_GET['blog_comments'] = (bool) $data['comments'];
        $action = array_shift($_GET['param']);
        if ($action == '' || $action == 'page') {
            // Show paged posts
            array_unshift($_GET['param'], 'page');
            if (count($_GET['param']) > 2) {
                ssc_not_found();
            }
            return _blog_gen_post($data['page'], $_GET['path'] . '/page/', "SELECT p.id, p.title, p.created, p.urltext, u.displayname author, count(c.post_id) count, p.body, p.commentsdisabled FROM\n\t\t\t\t#__blog_post p LEFT JOIN #__user u ON u.id = p.author_id LEFT JOIN #__blog_comment c ON (post_id = p.id AND (status & %d = 0))\n\t\t\t\tWHERE blog_id = %d AND p.is_draft = 0 GROUP BY p.id ORDER BY p.created DESC", SSC_BLOG_COMMENT_SPAM, $_GET['path-id']);
        } elseif ($action == 'tag') {
            // Show posts for the tag
            if (count($_GET['param']) == 2 || count($_GET['param']) > 3) {
                ssc_not_found();
            }
            $tag = array_shift($_GET['param']);
            if (empty($tag)) {
                ssc_not_found();
            }
            // If to parameter for the tag, die gracefully
            return _blog_gen_post($data['page'], $_GET['path'] . '/tag/' . $tag . '/page/', "SELECT p.id, p.title, p.created, p.urltext, u.displayname author, count(c.post_id) count, p.body, p.commentsdisabled FROM \n\t\t\t\t#__blog_post p LEFT JOIN #__user u ON u.id = p.author_id LEFT JOIN #__blog_comment c ON (post_id = p.id AND (status & %d = 0))\n\t\t\t\tLEFT JOIN #__blog_relation r ON r.post_id = p.id LEFT JOIN #__blog_tag t ON t.id = r.tag_id WHERE blog_id = %d AND p.is_draft = 0 AND t.tag = '%s'\n\t\t\t\tGROUP BY p.id ORDER BY p.created DESC", SSC_BLOG_COMMENT_SPAM, $_GET['path-id'], $tag);
        } elseif ($action == 'id') {
            // Redirect as needed
            if (count($_GET['param']) != 1) {
                ssc_not_found();
            }
            // Extra parameters
            $result = $ssc_database->query("SELECT created, urltext FROM #__blog_post WHERE id = %d AND is_draft = 0 LIMIT 1", (int) array_shift($_GET['param']));
            if ($data = $ssc_database->fetch_object($result)) {
                ssc_redirect($_GET['path'] . date("/Y/m/d/", $data->created) . $data->urltext, 301);
                return;
            }
            // Post ID doesn't exist - kill
            ssc_not_found();
        } elseif ($action == 'feed') {
            // Internal redirect to atom feed
            $feedPath = $ssc_site_path . '/modules/blog/atom-' . $_GET['path-id'] . '.xml';
            // Check if feed exists yet
            if (!file_exists($feedPath)) {
                ssc_not_found();
            }
            // Try and read it
            $rss = file_get_contents($feedPath);
            // See if read success?
            if ($rss === FALSE) {
                ssc_not_found();
            }
            // Guess not - die gracefully
            // Output rss
            header("Content-Type: application/xml", true);
            echo $rss;
            // And now quit ...
            ssc_close();
            // ... fully
            exit(0);
        } elseif ($action == 'atom') {
            if (count($_GET['param']) > 1) {
                ssc_not_found();
            }
            header("Content-Type: application/atom+xml", true);
            include $ssc_site_path . '/modules/blog/rss.inline.php';
            ssc_close();
            exit(0);
        } else {
            // Not those - is int?
            $action = (int) $action;
            // Check for bad first param
            if ($action == 0) {
                ssc_not_found();
                return;
            }
            // Check if the post name exists?
            if (!empty($_GET['param'][2])) {
                // Retrieve post
                $result = $ssc_database->query("SELECT p.id, p.title, p.created, p.urltext, p.commentsdisabled, u.displayname author, p.body FROM #__blog_post p \n\t\t\t\t\tLEFT JOIN #__user u ON u.id = p.author_id WHERE blog_id = %d AND p.is_draft = 0 AND p.urltext = '%s' \n\t\t\t\t\tLIMIT 1", $_GET['path-id'], $_GET['param'][2]);
                if (!($data = $ssc_database->fetch_object($result))) {
                    // No post with name - kill output
                    ssc_not_found();
                    return;
                }
                // Don't allow any further params
                if (!empty($_GET['param'][3])) {
                    // Unless admin, and the param is 'mark'
                    if (login_check_auth("blog") && $_GET['param'][3] == 'mark') {
                        if ($ssc_database->query("UPDATE #__blog_comment SET status = status | %d WHERE post_id = %d", SSC_BLOG_COMMENT_READ, $data->id)) {
                            ssc_add_message(SSC_MSG_INFO, t('Marked the comments as read'));
                        }
                    } else {
                        ssc_not_found();
                        return;
                    }
                }
                // Comments disabled flag
                $comments_disabled = $data->commentsdisabled;
                // Post id number
                $pid = $data->id;
                $out = "\n<h3>{$data->title}</h3>\n";
                $out .= t("Posted !date at !time by !author\n", array('!date' => date(ssc_var_get('date_med', SSC_DATE_MED), $data->created), '!time' => date(ssc_var_get('time_short', SSC_TIME_SHORT), $data->created), '!author' => $data->author)) . '<br />';
                $result = $ssc_database->query("SELECT tag FROM #__blog_relation r, #__blog_tag t WHERE r.tag_id = t.id AND r.post_id = %d ORDER BY tag ASC", $data->id);
                // Retrieve list of tags for the post
                if ($ssc_database->number_rows()) {
                    $out .= "Tagged: ";
                    $txt = '';
                    while ($dat = $ssc_database->fetch_object($result)) {
                        $txt .= ', ' . l($dat->tag, $_GET['path'] . '/tag/' . $dat->tag);
                    }
                    $txt = substr($txt, 2);
                    $out .= $txt . '<br />';
                }
                $out .= sscText::convert($data->body);
                if ($_GET['blog_comments']) {
                    // Retrieve comments
                    $out .= '<div class="clear"></div><h3 id="comments">Comments</h3>';
                    // Are we admin?
                    $is_admin = login_check_auth("blog");
                    if ($is_admin) {
                        $result = $ssc_database->query("SELECT id, author, email, site, created, status, body FROM #__blog_comment \n\t\t\t\t\t\tWHERE post_id = %d ORDER BY created ASC", $data->id, SSC_BLOG_COMMENT_SPAM, SSC_BLOG_COMMENT_SPAM);
                        // Start spam/ham/commentstate form
                        $out .= '<form action="" method="post"><div><input type="hidden" name="form-id" value="blog_spam_ham" />';
                        // Show (dis-)enable comments button on posts with or without comments
                        if ($comments_disabled == 0) {
                            $sub_disable_comments = array('#value' => 'Disable Comments', '#type' => 'submit', '#name' => "disable_comments[{$pid}]");
                        } else {
                            $sub_disable_comments = array('#value' => 'Enable Comments', '#type' => 'submit', '#name' => "enable_comments[{$pid}]");
                        }
                        // Render button
                        $out .= theme_render_input($sub_disable_comments);
                    } else {
                        $result = $ssc_database->query("SELECT author, email, site, created, body FROM #__blog_comment \n\t\t\t\t\t\tWHERE post_id = %d AND status & %d = 0 ORDER BY created ASC", $data->id, SSC_BLOG_COMMENT_SPAM);
                    }
                    if (!$result || $ssc_database->number_rows($result) == 0) {
                        // Bad SQL
                        $out .= t('There are no comments posted yet.');
                    } else {
                        // Admin user - show spam/ham/commentstate options
                        if ($is_admin) {
                            // For each comment, show it, it's visible state, and possible options
                            while ($data = $ssc_database->fetch_object($result)) {
                                $status = $data->status;
                                $out .= "<div class='" . ($status & SSC_BLOG_COMMENT_SPAM ? "blog-spam-icon" : "blog-notspam-icon") . "'><p>" . nl2br(check_plain($data->body)) . "</p><p>";
                                $out .= t("Posted !date at !time by !author\n", array('!date' => date(ssc_var_get('date_med', SSC_DATE_MED), $data->created), '!time' => date(ssc_var_get('time_short', SSC_TIME_SHORT), $data->created), '!author' => empty($data->site) ? check_plain($data->author) : l(check_plain($data->author), $data->site))) . '</p>';
                                $sub_hide = array('#value' => 'Hide comment', '#type' => 'submit');
                                $sub_show = array('#value' => 'Show comment', '#type' => 'submit');
                                $sub_spam = array('#value' => 'Mark spam', '#type' => 'submit');
                                $sub_ham = array('#value' => 'Unmark spam', '#type' => 'submit');
                                // If tree for actions
                                if ($status & SSC_BLOG_COMMENT_CAN_SPAM) {
                                    // Hasn't been re-submitted yet
                                    if ($status & SSC_BLOG_COMMENT_SPAM) {
                                        // Was marked as spam
                                        $sub_ham['#name'] = "ham[{$data->id}]";
                                        $out .= theme_render_input($sub_ham);
                                        $sub_show['#name'] = "show[{$data->id}]";
                                        $out .= theme_render_input($sub_show);
                                    } else {
                                        // Was not marked spam
                                        $sub_spam['#name'] = "spam[{$data->id}]";
                                        $out .= theme_render_input($sub_spam);
                                        $sub_hide['#name'] = "hide[{$data->id}]";
                                        $out .= theme_render_input($sub_hide);
                                    }
                                } else {
                                    // Has already been resubmitted
                                    if ($status & SSC_BLOG_COMMENT_SPAM) {
                                        // Currently spam/hidden
                                        $sub_show['#name'] = "show[{$data->id}]";
                                        $out .= theme_render_input($sub_show);
                                    } else {
                                        // Marked as normal currently
                                        $sub_hide['#name'] = "hide[{$data->id}]";
                                        $out .= theme_render_input($sub_hide);
                                    }
                                }
                                $out .= '</div><hr />';
                            }
                        } else {
                            // Just show comments
                            while ($data = $ssc_database->fetch_object($result)) {
                                //$out .= "<div class='gravatar' style='background-image: url(\""._blog_gravatar_get_url($data->email)."\");'>";
                                $out .= '<p>' . nl2br(check_plain($data->body)) . '</p><p>';
                                $out .= t("Posted !date at !time by !author\n", array('!date' => date(ssc_var_get('date_med', SSC_DATE_MED), $data->created), '!time' => date(ssc_var_get('time_short', SSC_TIME_SHORT), $data->created), '!author' => empty($data->site) ? $data->author : l($data->author, $data->site))) . '</p><hr />';
                                //'</p></div><hr />';
                            }
                        }
                    }
                    // End admin form
                    if ($is_admin) {
                        $out .= '</div></form>';
                    }
                    if ($comments_disabled == 0 || $is_admin) {
                        $out .= ssc_generate_form('blog_guest_comment', $pid);
                    } else {
                        $out .= '<br />' . t("Sorry, commenting has been closed on this post.");
                    }
                }
                return $out;
            } elseif (isset($_GET['param'][0])) {
                // First param set not expecting anything - kill page
                ssc_not_found();
                return;
            } else {
                // Yearly archive
                return _blog_gen_post(10000, $_GET['path'] . '/page/', "SELECT p.id, p.title, p.created, p.urltext, u.displayname author, count(c.post_id) count, p.commentsdisabled FROM \n\t\t\t\t\t#__blog_post p LEFT JOIN #__blog_comment c ON (post_id = p.id AND (c.status & %d = 0)) LEFT JOIN #__user u ON u.id = p.author_id \n\t\t\t\t\tWHERE blog_id = %d AND p.created >= %d AND p.created < %d AND p.is_draft = 0 GROUP BY p.id ORDER BY p.created DESC", SSC_BLOG_COMMENT_SPAM, $_GET['path-id'], mktime(0, 0, 0, 1, 1, $action), mktime(0, 0, 0, 1, 0, $action + 1));
            }
        }
    }
    // Find content
    ssc_not_found();
}
Example #4
0
/**
 * Gallery content modification form
 */
function gallery_form()
{
    global $ssc_database, $ssc_site_url;
    if (isset($_GET['param'][0])) {
        $galID = (int) array_shift($_GET['param']);
    }
    if (!empty($_POST['form-id']) && $_POST['form-id'] == 'gallery_form') {
        $data = new stdClass();
        $data->name = empty($_POST['name']) ? '' : $_POST['name'];
        $data->descr = empty($_POST['desc']) ? '' : $_POST['desc'];
        $data->visible = empty($_POST['vis']) ? 0 : (int) $_POST['vis'];
        $data->path = empty($_POST['url']) ? '' : $_POST['url'];
    } elseif ($galID > 0) {
        $result = $ssc_database->query("SELECT path, title name, description descr, visible FROM #__gallery g \n\t\t\tLEFT JOIN #__handler h ON h.id = g.id WHERE h.id = %d LIMIT 1", $galID);
        if (!$result || !($data = $ssc_database->fetch_object($result))) {
            // Something borked
            $data = new stdClass();
            $data->name = '';
            $data->descr = '';
            $data->visible = 1;
            $data->path = '';
        }
    } else {
        // New
        $data = new stdClass();
        $data->name = '';
        $data->descr = '';
        $data->visible = 1;
        $data->path = '';
        $galID = 0;
    }
    $form = array('#action' => '', '#method' => 'post', '#attributes' => array('enctype' => 'multipart/form-data'));
    $fieldset =& $form['details'];
    $fieldset = array('#type' => 'fieldset', '#title' => t('Gallery details'), '#parent' => true);
    $fieldset['name'] = array('#title' => t('Gallery name'), '#description' => t('Name to display at top of the page'), '#type' => 'text', '#required' => true, '#value' => $data->name);
    $fieldset['url'] = array('#type' => 'text', '#value' => $data->path, '#title' => t('Path to gallery'), '#required' => true, '#description' => t('Path that should be used to access the gallery.  Should exclude \'!site\'', array('!site' => $ssc_site_url . '/')));
    $fieldset['desc'] = array('#type' => 'textarea', '#title' => t('Gallery description'), '#description' => t('Short optional description relating to the gallery.  Plain-text only!'), '#value' => $data->descr);
    $fieldset['vis'] = array('#type' => 'checkbox', '#title' => t('Enabled'), '#description' => t('If checked, the gallery will be enabled for viewing'), '#value' => 1, '#checked' => $data->visible);
    $fieldset['gid'] = array('#type' => 'hidden', '#value' => $galID);
    $fieldset['sub'] = array('#type' => 'submit', '#value' => t('Save changes'));
    $fieldset['rev'] = array('#type' => 'reset', '#value' => t('Revert changes'));
    // Return only first half for new gallery
    if ($galID == 0) {
        return $form;
    }
    $fieldset =& $form['upload'];
    $fieldset = array('#type' => 'fieldset', '#title' => t('Upload photos'), '#parent' => true);
    $fieldset['single'] = array('#type' => 'file', '#title' => t('Upload single image'), '#description' => t('Add a single image to the gallery.  Image will be automatically resized as needed.'));
    $fieldset['sub'] = array('#type' => 'submit', '#value' => t('Save and upload'));
    $result = $ssc_database->query("SELECT id, caption, mid FROM #__gallery_content WHERE gallery_id = %d", $galID);
    if (!$result) {
        return $form;
    }
    $fieldset =& $form['content'];
    $fieldset = array('#type' => 'fieldset', '#title' => t('Gallery content'), '#parent' => true);
    // Generate caption listing
    $input = array('#type' => 'text', '#maxlength' => 150);
    $input_border = array('#title' => t('Caption'), '#description' => t('Short caption for the image'));
    while ($data = $ssc_database->fetch_object($result)) {
        $input['#name'] = "item[{$data->id}][cap]";
        $input['#value'] = $data->caption;
        $input_border['#value'] = theme_render_input($input);
        $out = "<div class=\"form-img\"><img src=\"{$ssc_site_url}/images/gallery/{$galID}/{$data->id}_t\" alt=\"\" />";
        $out .= theme_render_form_element($input_border);
        $out .= '</div>';
        $fieldset["item{$data->id}"] = array('#type' => '', '#value' => $out);
    }
    return $form;
}
Example #5
0
/**
* Form processing
* @param string $form_name Name of the form in the form of 'module_formname' representing the
* 					function to call to generate said form
*
function ssc_form_handler($form_name){

	//return ssc_generate_html($form_name());
}

/**
* Display a structured array of html elements
* @param array $structure Array of html elements and element properties
*/
function ssc_generate_html(&$structure)
{
    $out = '';
    // Get keys
    $keys = array_keys($structure);
    rsort($keys);
    if (isset($structure['#parent'])) {
        // Generate the field content
        foreach ($structure as $tag => $value) {
            if ($tag[0] == '#') {
                continue;
            }
            $value['#name'] = $tag;
            if (empty($value['#id'])) {
                $value['#id'] = $structure['#formname'] . "-{$tag}";
            }
            $value['#formname'] = $structure['#formname'];
            $out .= ssc_generate_html($value);
            unset($structure[$tag]);
        }
        $structure['#value'] = $out;
        $out = '';
    }
    $hook = 'theme_render_' . $structure['#type'];
    if (function_exists($hook)) {
        $out = $hook($structure);
    } else {
        switch ($structure['#type']) {
            case 'text':
            case 'password':
            case 'file':
                $structure['#value'] = theme_render_input($structure);
                $out = theme_render_form_element($structure);
                break;
            case 'hidden':
            case 'submit':
            case 'reset':
                $out = theme_render_input($structure);
                break;
            default:
                $out = $structure['#value'];
        }
    }
    return $out;
}