protected function subscribeLabel($id = '', $class = 'main', $checked = true) { // Create subscribe checkbox label element $subscribe_label = new HTMLTag('label'); $subscribe_label->createAttribute('for', 'hashover-subscribe'); if (!empty($id)) { $subscribe_label->appendAttribute('for', '-' . $this->injectVar($id), false); } $subscribe_label->createAttribute('class', 'hashover-' . $class . '-label'); $subscribe_label->createAttribute('title', $this->locales->locale('subscribe_tip', $this->addcslashes)); // Create subscribe element checkbox $subscribe = new HTMLTag('input', true); $subscribe->createAttribute('id', 'hashover-subscribe'); if (!empty($id)) { $subscribe->appendAttribute('id', '-' . $this->injectVar($id), false); } $subscribe->createAttribute('type', 'checkbox'); $subscribe->createAttribute('name', 'subscribe'); // Check checkbox if ($checked) { $subscribe->createAttribute('checked', 'true'); } // Add subscribe checkbox element to subscribe checkbox label element $subscribe_label->appendChild($subscribe); // Add text to subscribe checkbox label element $subscribe_label->appendInnerHTML($this->locales->locale('subscribe', $this->addcslashes)); return $subscribe_label; }
public function initialHTML($hashover_wrapper = true) { // Create element that HashOver comments will appear in $hashover_element = new HTMLTag('div', false, false); $hashover_element->createAttribute('id', 'hashover'); // Add class for differentiating desktop and mobile styling if ($this->setup->isMobile === true) { $hashover_element->appendAttribute('class', 'hashover-mobile'); } else { $hashover_element->appendAttribute('class', 'hashover-desktop'); } // Add class to indicate user login status if ($this->setup->userIsLoggedIn === true) { $hashover_element->appendAttribute('class', 'hashover-logged-in'); } else { $hashover_element->appendAttribute('class', 'hashover-logged-out'); } // Create element for jump anchor $jump_anchor = new HTMLTag('span'); $jump_anchor->createAttribute('id', 'comments'); // Add jump anchor to HashOver element $hashover_element->appendChild($jump_anchor); // Create primary form wrapper element $form_section = new HTMLTag('div', false, false); $form_section->createAttribute('id', 'hashover-form-section'); // Create element for "Post Comment" title $post_title = new HTMLTag('span'); $post_title->createAttribute('class', 'hashover-title'); $post_title->appendAttribute('class', 'hashover-main-title'); $post_title->appendAttribute('class', 'hashover-dashed-title'); $post_comment_locale = $this->locales->locale('post_comment_on', $this->addcslashes); $post_title->innerHTML($post_comment_locale[0]); // Add optional "on <page title>" to "Post Comment" title if ($this->setup->displaysTitle === true) { $on_title = str_replace('_TITLE_', $this->pageTitle, $post_comment_locale[1]); $post_title->appendInnerHTML($on_title, false); } // Add "Post Comment" element to primary form wrapper $form_section->appendChild($post_title); // Create element for various messages when needed $message_element = new HTMLTag('div'); $message_element->createAttribute('id', 'hashover-message'); $message_element->createAttribute('class', 'hashover-title'); $message_element->appendAttribute('class', 'hashover-message'); // Check if message cookie is set if (!empty($_COOKIE['message']) or !empty($_COOKIE['error'])) { if ($this->setup->mode === 'php') { $message_element->appendAttribute('class', 'hashover-message-open'); } if (!empty($_COOKIE['message'])) { $message = $_COOKIE['message']; } else { $message = $_COOKIE['error']; $message_element->appendAttribute('class', 'hashover-message-error'); } // If so, put current message into message element $message_element->innerHTML($message); } // Add message element to primary form wrapper $form_section->appendChild($message_element); // Create main HashOver form $main_form = new HTMLTag('form'); $main_form->createAttribute('id', 'hashover-form'); $main_form->createAttribute('class', 'hashover-balloon'); $main_form->createAttribute('name', 'hashover-form'); $main_form->createAttribute('action', $_SERVER['PHP_SELF']); $main_form->createAttribute('method', 'post'); // Create wrapper element for styling inputs $main_inputs = new HTMLTag('div'); $main_inputs->createAttribute('class', 'hashover-inputs'); // If avatars are enabled if ($this->setup->iconMode !== 'none') { // Create avatar element for main HashOver form $main_avatar = new HTMLTag('div'); $main_avatar->createAttribute('class', 'hashover-avatar-image'); // Add count element to avatar element $main_avatar->appendChild($this->avatar($this->readComments->primaryCount)); // Add avatar element to inputs wrapper element $main_inputs->appendChild($main_avatar); } // Logged in if ($this->setup->userIsLoggedIn === true) { if (!empty($this->setup->userName)) { $user_name = $this->setup->userName; } else { $user_name = $this->setup->defaultName; } $user_website =& $this->setup->userWebsite; $name_class = 'hashover-name-plain'; $is_twitter = false; // Check if user's name is a Twitter handle if ($user_name[0] === '@') { $user_name = substr($user_name, 1); $name_class = 'hashover-name-twitter'; $is_twitter = true; $name_length = mb_strlen($user_name); if ($name_length > 1 and $name_length <= 30) { if (empty($user_website)) { $user_website = 'http://twitter.com/' . $user_name; } } } // Create element for logged user's name $main_form_column_spanner = new HTMLTag('div', false, false); $main_form_column_spanner->createAttribute('class', 'hashover-comment-name'); $main_form_column_spanner->appendAttribute('class', 'hashover-top-name'); // Check if user gave website if (!empty($user_website)) { if ($is_twitter === false) { $name_class = 'hashover-name-website'; } // Create link to user's website $main_form_hyperlink = new HTMLTag('a', false, false); $main_form_hyperlink->createAttribute('href', $user_website); $main_form_hyperlink->createAttribute('target', '_blank'); $main_form_hyperlink->innerHTML($user_name); // Add username hyperlink to main form column spanner $main_form_column_spanner->appendChild($main_form_hyperlink); } else { // No website $main_form_column_spanner->innerHTML($user_name); } // Set classes user's name spanner $main_form_column_spanner->appendAttribute('class', $name_class); // Add main form column spanner to inputs wrapper element $main_inputs->appendChild($main_form_column_spanner); } else { // Logged out // Use default login inputs $main_inputs->appendInnerHTML($this->defaultLoginInputs->innerHTML); } // Add inputs wrapper to form element $main_form->appendChild($main_inputs); // Create fake "required fields" element as a SPAM trap $required_fields = new HTMLTag('div'); $required_fields->createAttribute('id', 'hashover-requiredFields'); $fake_fields = array('summary' => 'text', 'age' => 'hidden', 'lastname' => 'text', 'address' => 'text', 'zip' => 'hidden'); // Create and append fake input elements to fake required fields foreach ($fake_fields as $name => $type) { $fake_input = new HTMLTag('input', true); $fake_input->createAttribute('type', $type); $fake_input->createAttribute('name', $name); $fake_input->createAttribute('value'); // Add fake summary input element to fake required fields $required_fields->appendChild($fake_input); } // Add fake input elements to form element $main_form->appendChild($required_fields); // Create label element for comment textarea if ($this->setup->usesLabels === true) { $main_comment_label = new HTMLTag('label', false, false); $main_comment_label->createAttribute('for', 'hashover-main-comment'); $main_comment_label->createAttribute('class', 'hashover-comment-label'); $main_comment_label->innerHTML($this->locales->locale('comment_form', $this->addcslashes)); // Add comment label to form element $main_form->appendChild($main_comment_label); } // Create main textarea $main_textarea = new HTMLTag('textarea'); $main_textarea->createAttribute('id', 'hashover-main-comment'); $main_textarea->createAttribute('class', 'hashover-textarea'); $main_textarea->appendAttribute('class', 'hashover-main-textarea'); $main_textarea->createAttribute('cols', '63'); $main_textarea->createAttribute('name', 'comment'); $main_textarea->createAttribute('rows', '5'); $main_textarea->createAttribute('title', $this->locales->locale('form_tip', $this->addcslashes)); $main_textarea->createAttribute('placeholder', $this->locales->locale('comment_form', $this->addcslashes)); // Add a red border to main textarea upon posting error if (isset($_COOKIE['success']) and $_COOKIE['success'] === 'no') { $main_textarea->createAttribute('style', 'border: 2px solid #FF0000 !important;'); $main_textarea->createAttribute('placeholder', $this->locales->locale('reply_form', $this->addcslashes)); } // Add main textarea element to form element $main_form->appendChild($main_textarea); // Create hidden page title input element $main_page_title_input = new HTMLTag('input', true); $main_page_title_input->createAttribute('type', 'hidden'); $main_page_title_input->createAttribute('name', 'title'); $main_page_title_input->createAttribute('value', $this->pageTitle); // Add hidden page title input element to form element $main_form->appendChild($main_page_title_input); // Create hidden page URL input element $main_page_url_input = new HTMLTag('input', true); $main_page_url_input->createAttribute('type', 'hidden'); $main_page_url_input->createAttribute('name', 'url'); $main_page_url_input->createAttribute('value', $this->pageURL); // Add hidden page title input element to form element $main_form->appendChild($main_page_url_input); // Create hidden reply to input element if (!empty($_COOKIE['replied'])) { $reply_to_input = new HTMLTag('input', true); $reply_to_input->createAttribute('type', 'hidden'); $reply_to_input->createAttribute('name', 'reply_to'); $reply_to_input->createAttribute('value', $_COOKIE['replied']); // Add hidden reply to input element to form element $main_form->appendChild($reply_to_input); } // Create wrapper element for main form footer $main_form_footer = new HTMLTag('div'); $main_form_footer->createAttribute('class', 'hashover-form-footer'); // Add checkbox label element to main form buttons wrapper element if ($this->setup->allowsEmails !== false) { if ($this->setup->userIsLoggedIn === false or !empty($this->setup->userEmail)) { $main_form_footer->appendChild($this->subscribeLabel()); } } // Create wrapper for form buttons $main_form_buttons_wrapper = new HTMLTag('span'); $main_form_buttons_wrapper->createAttribute('class', 'hashover-form-buttons'); // Create "Login" / "Logout" button element if ($this->setup->allowsLogin !== false or $this->setup->userIsLoggedIn === true) { $login_button = new HTMLTag('input', true); $login_button->createAttribute('id', 'hashover-login-button'); $login_button->createAttribute('class', 'hashover-submit'); $login_button->createAttribute('type', 'submit'); // Logged in if ($this->setup->userIsLoggedIn === true) { $login_button->appendAttribute('class', 'hashover-logout'); $login_button->createAttribute('name', 'logout'); $login_button->createAttribute('value', $this->locales->locale('logout', $this->addcslashes)); $login_button->createAttribute('title', $this->locales->locale('logout', $this->addcslashes)); } else { // Logged out $login_button->appendAttribute('class', 'hashover-login'); $login_button->createAttribute('name', 'login'); $login_button->createAttribute('value', $this->locales->locale('login', $this->addcslashes)); $login_button->createAttribute('title', $this->locales->locale('login_tip', $this->addcslashes)); } // Add "Login" / "Logout" element to main form footer element $main_form_buttons_wrapper->appendChild($login_button); } // Create "Post Comment" button element $main_post_button = new HTMLTag('input', true); $main_post_button->createAttribute('id', 'hashover-post-button'); $main_post_button->createAttribute('class', 'hashover-submit'); $main_post_button->appendAttribute('class', 'hashover-post-button'); $main_post_button->createAttribute('type', 'submit'); $main_post_button->createAttribute('name', 'post'); $main_post_button->createAttribute('value', $this->locales->locale('post_button', $this->addcslashes)); $main_post_button->createAttribute('title', $this->locales->locale('post_button', $this->addcslashes)); // Add "Post Comment" element to main form buttons wrapper element $main_form_buttons_wrapper->appendChild($main_post_button); // Add main form button wrapper to main form footer element $main_form_footer->appendChild($main_form_buttons_wrapper); // Add main form footer to main form element $main_form->appendChild($main_form_footer); // Add main form element to primary form wrapper $form_section->appendChild($main_form); // Check if form position setting set to 'top' if ($this->setup->formPosition === 'top') { // Add primary form wrapper to HashOver element $hashover_element->appendChild($form_section); } if (!empty($this->popularList)) { // Create wrapper element for popular comments $popular_section = new HTMLTag('div', false, false); $popular_section->createAttribute('id', 'hashover-popular-section'); // Create wrapper element for popular comments title $pop_count_wrapper = new HTMLTag('div'); $pop_count_wrapper->createAttribute('class', 'hashover-dashed-title'); // Create element for popular comments title $pop_count_element = new HTMLTag('span'); $pop_count_element->createAttribute('class', 'hashover-title'); $popPlural = count($this->popularList) !== 1 ? 1 : 0; $popular_comments_locale = $this->locales->locale('popular_comments', $this->addcslashes); $pop_count_element->innerHTML($popular_comments_locale[$popPlural]); // Add popular comments title element to wrapper element $pop_count_wrapper->appendChild($pop_count_element); // Add popular comments title wrapper element to popular comments section $popular_section->appendChild($pop_count_wrapper); // Create element for popular comments to appear in $popular_comments = new HTMLTag('div', false, false); $popular_comments->createAttribute('id', 'hashover-top-comments'); // Add comments to HashOver element if (!empty($this->popularComments)) { $popular_comments->innerHTML(trim($this->popularComments)); } // Add popular comments element to popular comments section $popular_section->appendChild($popular_comments); // Add popular comments section to HashOver element $hashover_element->appendChild($popular_section); } // Create wrapper element for comments $comments_section = new HTMLTag('div', false, false); $comments_section->createAttribute('id', 'hashover-comments-section'); // Create wrapper element for comment count and sort dropdown menu if ($this->readComments->totalCount > 1) { $count_sort_wrapper = new HTMLTag('div'); $count_sort_wrapper->createAttribute('class', 'hashover-sort-count'); $count_sort_wrapper->appendAttribute('class', 'hashover-dashed-title'); // Create element for comment count $count_element = new HTMLTag('span'); $count_element->createAttribute('id', 'hashover-count'); $count_element->innerHTML($this->commentCount); // Hide comment count if collapse limit is set at zero if ($this->setup->mode === 'javascript') { if ($this->setup->collapseLimit <= 0) { $count_element->createAttribute('style', 'display: none;'); } } // Add comment count element to wrapper element $count_sort_wrapper->appendChild($count_element); // JavaScript mode specific HTML if ($this->readComments->totalCount > 2 and $this->setup->mode === 'javascript') { // Create wrapper element for sort dropdown menu $sort_wrapper = new HTMLTag('span'); $sort_wrapper->createAttribute('id', 'hashover-sort'); // Hide comment count if collapse limit is set at zero if ($this->setup->collapseLimit <= 0) { $sort_wrapper->createAttribute('style', 'display: none;'); } // Create sort dropdown menu element $sort_select = new HTMLTag('select'); $sort_select->createAttribute('id', 'hashover-sort-select'); $sort_select->createAttribute('name', 'sort'); $sort_select->createAttribute('size', '1'); // Array of select tag sort options $sort_options = array(array('value' => 'ascending', 'innerHTML' => $this->locales->locale('sort_ascend', $this->addcslashes)), array('value' => 'descending', 'innerHTML' => $this->locales->locale('sort_descend', $this->addcslashes)), array('value' => 'byDate', 'innerHTML' => $this->locales->locale('sort_bydate', $this->addcslashes)), array('value' => 'byName', 'innerHTML' => $this->locales->locale('sort_byname', $this->addcslashes)), array('value' => 'byLikes', 'innerHTML' => $this->locales->locale('sort_bylikes', $this->addcslashes))); // Create sort options for sort dropdown menu element for ($i = 0, $il = count($sort_options); $i < $il; $i++) { $option = new HTMLTag('option', false, false); $option->createAttribute('value', $sort_options[$i]['value']); $option->innerHTML($sort_options[$i]['innerHTML']); // Add sort option element to sort dropdown menu $sort_select->appendChild($option); } // Create empty option group as spacer $spacer_optgroup = new HTMLTag('optgroup'); $spacer_optgroup->createAttribute('label', ' '); // Add spacer option group to sort dropdown menu $sort_select->appendChild($spacer_optgroup); // Create option group for threaded sort options $threaded_optgroup = new HTMLTag('optgroup'); $threaded_optgroup->createAttribute('label', $this->locales->locale('threaded', $this->addcslashes)); // Array of select tag threaded sort options $threaded_sort_options = array(array('value' => 'threadedDescending', 'innerHTML' => $this->locales->locale('sort_descend', $this->addcslashes)), array('value' => 'threadedByDate', 'innerHTML' => $this->locales->locale('sort_bydate', $this->addcslashes)), array('value' => 'threadedByName', 'innerHTML' => $this->locales->locale('sort_byname', $this->addcslashes)), array('value' => 'threadedByLikes', 'innerHTML' => $this->locales->locale('sort_bylikes', $this->addcslashes))); // Create sort options for sort dropdown menu element for ($i = 0, $il = count($threaded_sort_options); $i < $il; $i++) { $option = new HTMLTag('option', false, false); $option->createAttribute('value', $threaded_sort_options[$i]['value']); $option->innerHTML($threaded_sort_options[$i]['innerHTML']); // Add sort option element to threaded option group $threaded_optgroup->appendChild($option); } // Add threaded sort options group to sort dropdown menu $sort_select->appendChild($threaded_optgroup); // Add sort dropdown menu element to sort wrapper element $sort_wrapper->appendChild($sort_select); // Add comment count element to wrapper element $count_sort_wrapper->appendChild($sort_wrapper); } // Add comment count and sort dropdown menu wrapper to comments section $comments_section->appendChild($count_sort_wrapper); } // Create element that will hold the comments $sort_div = new HTMLTag('div', false, false); $sort_div->createAttribute('id', 'hashover-sort-div'); // Add comments to HashOver element if (!empty($this->comments)) { $sort_div->innerHTML(trim($this->comments)); } // Add comments element to comments section $comments_section->appendChild($sort_div); // Add comments element to HashOver element $hashover_element->appendChild($comments_section); // Check if form position setting set to 'bottom' if ($this->setup->formPosition === 'bottom') { // Add primary form wrapper to HashOver element $hashover_element->appendChild($form_section); } // Create end links wrapper element $end_links_wrapper = new HTMLTag('div'); $end_links_wrapper->createAttribute('id', 'hashover-end-links'); // Create link back to HashOver homepage (fixme! get a real page!) $hashover_home_link = new HTMLTag('a', false, false); $hashover_home_link->createAttribute('href', 'http://tildehash.com/?page=hashover'); $hashover_home_link->createAttribute('id', 'hashover-home-link'); $hashover_home_link->createAttribute('target', '_blank'); $hashover_home_link->innerHTML('HashOver Comments'); // Add link back to HashOver homepage to end links wrapper element $end_links_wrapper->appendChild($hashover_home_link); $end_links_wrapper->appendInnerHTML(' ‒', false); if ($this->readComments->totalCount > 1) { if ($this->setup->displaysRSSLink === true) { if ($this->setup->APIStatus('rss') !== 'disabled') { // Create RSS feed link $hashover_rss_link = new HTMLTag('a', false, false); $hashover_rss_link->createAttribute('href', $this->setup->httpDirectory . '/api/rss.php'); $hashover_rss_link->appendAttribute('href', '?url=' . $this->safeURLEncode($this->setup->pageURL), false); $hashover_rss_link->createAttribute('id', 'hashover-rss-link'); $hashover_rss_link->createAttribute('target', '_blank'); $hashover_rss_link->innerHTML('RSS Feed'); // Add RSS feed link to end links wrapper element $end_links_wrapper->appendChild($hashover_rss_link); $end_links_wrapper->appendInnerHTML(' ·', false); } } } // Create link to HashOver source code (fixme! can be done better) $hashover_source_link = new HTMLTag('a', false, false); $hashover_source_link->createAttribute('href', $this->setup->httpDirectory . '/scripts/hashover.php?source'); $hashover_source_link->createAttribute('id', 'hashover-source-link'); $hashover_source_link->createAttribute('rel', 'hashover-source'); $hashover_source_link->createAttribute('target', '_blank'); $hashover_source_link->innerHTML('Source Code'); // Add link to HashOver source code to end links wrapper element $end_links_wrapper->appendChild($hashover_source_link); // Create link to HashOver JavaScript source code if ($this->setup->mode === 'javascript') { // First add a middot character $end_links_wrapper->appendInnerHTML(' ·', false); $hashover_javascript_link = new HTMLTag('a', false, false); $hashover_javascript_link->createAttribute('href', $this->setup->httpDirectory . '/scripts/hashover-javascript.php'); $hashover_javascript_link->appendAttribute('href', '?url=' . $this->safeURLEncode($this->setup->pageURL), false); $hashover_javascript_link->appendAttribute('href', '&title=' . $this->safeURLEncode($this->setup->pageTitle), false); if (!empty($_GET['hashover-script'])) { $hashover_javascript_link->appendAttribute('href', '&hashover-script=' . $this->safeURLEncode($_GET['hashover-script']), false); } $hashover_javascript_link->createAttribute('id', 'hashover-javascript-link'); $hashover_javascript_link->createAttribute('rel', 'hashover-javascript'); $hashover_javascript_link->createAttribute('target', '_blank'); $hashover_javascript_link->innerHTML('JavaScript'); // Add link to HashOver JavaScript source code to end links wrapper element $end_links_wrapper->appendChild($hashover_javascript_link); } // Add end links wrapper element to HashOver element $hashover_element->appendChild($end_links_wrapper); // Return all HTML with the HashOver wrapper element if ($hashover_wrapper === true) { return $hashover_element->asHTML(); } // Return just the HashOver wrapper element's innerHTML return $hashover_element->innerHTML; }