function ozh_ta_setting($setting) { // get setting value global $ozh_ta; $value = $ozh_ta[$setting]; // echo the field switch ($setting) { case 'screen_name': case 'cons_key': case 'cons_secret': $value = esc_attr($value); echo "<input id='{$setting}' name='ozh_ta[{$setting}]' type='text' value='{$value}' />"; break; $value = esc_attr($value); echo "<input id='{$setting}' name='ozh_ta[{$setting}]' type='text' value='{$value}' />"; break; case 'refresh_interval': $options = array('300' => 'every 5 minutes', '900' => 'every 15 minutes', '3600' => 'hourly', '43200' => 'twice daily', '86400' => 'daily'); $value = absint($value); echo "<select id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>How often you want WordPress to check for new tweets and archive them.<br/>Ideally, select a frequency corresponding to 10 or 15 tweets."; break; case 'post_category': $value = absint($value); wp_dropdown_categories(array('hide_empty' => 0, 'name' => "ozh_ta[{$setting}]", 'orderby' => 'name', 'selected' => $value, 'hierarchical' => true)); echo "<br/>Posts will be filed into this category."; break; case 'post_format': $options = get_post_format_strings(); $value = array_key_exists($value, $options) ? $value : 'standard'; echo "<select class='toggler' id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>Posts will be assigned this post format."; break; case 'post_author': global $wpdb; $value = absint($value); $logins = $wpdb->get_results("SELECT ID as 'option', user_login as 'desc' FROM {$wpdb->users} ORDER BY user_login ASC"); echo "<select id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($logins as $login) { echo "<option value='{$login->option}' " . selected($login->option, $value, false) . ">{$login->desc}</option>\n"; } echo "</select>\n"; echo "<br/>Tweets will be assigned to this author."; break; case 'link_usernames': $options = array('no' => 'No', 'yes' => 'Yes'); $value = $value == 'yes' ? 'yes' : 'no'; echo "<select class='toggler' id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>Example: \"<span id='helper_link_usernames' class='tweet_sample'>Thank you\n\t\t<span id='toggle_link_usernames_no' class='toggle_link_usernames' style='display:" . ($value == 'no' ? 'inline' : 'none') . "'>@ozh</span>\n\t\t<span id='toggle_link_usernames_yes' class='toggle_link_usernames' style='display:" . ($value == 'yes' ? 'inline' : 'none') . "'>@<a href='https://twitter.com/ozh'>ozh</a></span>\n\t\tfor the #WordPress plugins!</span>\""; break; case 'un_tco': $options = array('no' => 'No', 'yes' => 'Yes'); $value = $value == 'yes' ? 'yes' : 'no'; echo "<select class='toggler' id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>Example: \"<span id='helper_un_tco' class='tweet_sample fade-303060 fade'>Wow super site \n\t\t<span id='toggle_un_tco_no' class='toggle_un_tco' style='display:" . ($value == 'no' ? 'inline' : 'none') . "'><a href='http://t.co/JeIYgZHB6o'>t.co/JeIYgZHB6o</a></span>\n\t\t<span id='toggle_un_tco_yes' class='toggle_un_tco' style='display:" . ($value == 'yes' ? 'inline' : 'none') . "'><a href='http://ozh.org/'>ozh.org</a></span>\n\t\t! Check it out!</span>\""; break; case 'embed_images': $options = array('no' => 'No', 'yes' => 'Yes'); $value = $value == 'yes' ? 'yes' : 'no'; echo "<select class='toggler' id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/><span id='helper_embed_images' class='tweet_sample fade-303060 fade'>\n\t\t<span id='toggle_embed_images_no' class='toggle_embed_images' style='display:" . ($value == 'no' ? 'inline' : 'none') . "'>Just display a link to the image</span>\n\t\t<span id='toggle_embed_images_yes' class='toggle_embed_images' style='display:" . ($value == 'yes' ? 'inline' : 'none') . "'>Display a link and an <img> after the text</span>\n\t\t</span>"; break; case 'link_hashtags': $options = array('no' => 'No', 'twitter' => 'Yes, pointing to Twitter search', 'local' => 'Yes, pointing to blog tag links here'); switch ($value) { case 'local': case 'twitter': case 'no': $value = $value; break; default: $value = 'no'; } echo "<select class='toggler' id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>Example: \"<span id='helper_link_hashtags' class='tweet_sample fade-303060 fade'>Thank you @ozh for the\n\t\t<span id='toggle_link_hashtags_no' class='toggle_link_hashtags' style='display:" . ($value == 'no' ? 'inline' : 'none') . "'>#WordPress</span>\n\t\t<span id='toggle_link_hashtags_twitter' class='toggle_link_hashtags' style='display:" . ($value == 'twitter' ? 'inline' : 'none') . "'><a href='http://search.twitter.com/search?q=%23WordPress'>#WordPress</a></span>\n\t\t<span id='toggle_link_hashtags_local' class='toggle_link_hashtags' style='display:" . ($value == 'local' ? 'inline' : 'none') . "'><a href='" . ozh_ta_get_tag_link('wordpress') . "'>#WordPress</a></span>\n\t\tplugins!</span>\""; break; case 'add_hash_as_tags': $options = array('no' => 'No', 'yes' => 'Yes'); $value = $value == 'yes' ? 'yes' : 'no'; echo "<select id='{$setting}' name='ozh_ta[{$setting}]'>\n"; foreach ($options as $option => $desc) { echo "<option value='{$option}' " . selected($option, $value, false) . ">{$desc}</option>\n"; } echo "</select>\n"; echo "<br/>If selected, tags in WordPress will be created with each #hashtags."; break; } }
/** * Convert hashtags: replace #blah with applicable HTML * * @param string $text Tweet text ("I am very nice #bleh") * @param string $hashtag Hashtag text ("bleh") * @return string Formatted HTML */ function ozh_ta_convert_hashtags($text, $hashtag) { global $ozh_ta; switch ($ozh_ta['link_hashtags']) { case 'twitter': $replace = sprintf('<span class="hashtag hashtag_twitter">#<a href="%s">%s</a></span>', 'https://twitter.com/search?q=%23' . $hashtag, $hashtag); break; case 'local': $replace = sprintf('<span class="hashtag hashtag_local">#<a href="%s">%s</a>', ozh_ta_get_tag_link($hashtag), $hashtag); break; case 'no': $replace = sprintf('<span class="hashtag hashtag_no">%s</span>', '#' . $hashtag); break; } $text = preg_replace('/\\#' . $hashtag . '/', $replace, $text, 1); return $text; }