Jump to content

liamdawe

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

liamdawe's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry to bump, but I am still stuck on this. What would be the best way to replace nested tags like that before the normal img tag converter?
  2. That's what I am trying to do in the code above, but it seems to not work correctly to the point of not parsing certain urls at all.
  3. Hi all currently I am parsing some simple bbcode like urls, images, bold etc. I have just added it so all images are turned into links to themselves so if the image is too big they can click on it for the full picture. The problem is if someone wants a picture to link to something other than itself that now doesn't work. I am trying to counter it by parsing images that have a manual url attached to them first like so: $find = array( "/\[url\=(.+?)\]\[img\](.+?)\[\/img\]\[\/url\]/is", ); $replace = array( "<a href=\"$1\" target=\"_blank\"><img src=\"$2\" class=\"bbcodeimage img-polaroid\" alt=\"image\" /></a>", ); $body = preg_replace($find, $replace, $body); The problem is it seems to mess up the rest of the url parsing, is there something I am doing wrong? This code is directly after to parse normal links, the above code seems to also mess this up: $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>" ); $body = preg_replace($find, $replace, $body);
  4. Hi all, I am currently trying to upgrade my websites search function, currently it will just list every article it finds with any of the words searched using PDO MySQL like so: $db->sqlquery("SELECT a.article_id, a.`title` , a.author_id, a.`date` , a.guest_username, u.username FROM `articles` a LEFT JOIN `users` u ON a.author_id = u.user_id WHERE a.active =1 AND MATCH ( a.`title` ) AGAINST ( ? IN BOOLEAN MODE ) ORDER BY a.date DESC LIMIT 0 , 30", array($search_text)); $found_search = $db->fetch_all_rows(); What I want to do is have a second option, where it searches for rows that have all of the words in it not just any of the words. $search_text contains the list of words separated by a space. Is this possible? Thanks!
  5. Wow so glad I came back here, that was quite genius and works exactly as expected, thanks a bunch!
  6. Currently I am using a custom-made simple bbcode parser I need to adjust to not parse anything inside code tags, so these: [code]do not parse any bbcode here like [b]this[/b][/code] I want nothing to be parsed inside those. My current code: function bbcode($body, $article = 1, $parse_links = 1) { if ($parse_links == 1) { $URLRegex = '/(??<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front $URLRegex.= '('; // Start capturing URL $URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol $URLRegex.= '[\w\d\.\/#\_\-\?:=]+'; // Any non-space character $URLRegex.= ')'; // Stop capturing URL $URLRegex.= '(??<![.,;!?:\"\'()-])(\/|\[|\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after $body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body); $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>" ); $body = preg_replace($find, $replace, $body); } else if ($parse_links == 0) { $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "$2", "$1" ); $body = preg_replace($find, $replace, $body); } // remove the new line after quotes, stop massive spacing $body = str_replace("[/quote]\r\n", '[/quote]', $body); // stop lists having a big gap at the top $body = str_replace("[ul]\r\n", '[ul]', $body); // Quoting an actual person, book or whatever $pattern = '/\[quote\=(.+?)\](.+?)\[\/quote\]/is'; $replace = "<blockquote><cite>$1</cite>$2</blockquote>"; while(preg_match($pattern, $body)) { $body = preg_replace($pattern, $replace, $body); } // Quote on its own $pattern = '/\[quote\](.+?)\[\/quote\]/is'; $replace = "<blockquote><cite>Quote</cite>$1</blockquote>"; while(preg_match($pattern, $body)) { $body = preg_replace($pattern, $replace, $body); } // replace images and youtube to the correct size if its a comment or forum post (less space!) if ($article == 0) { $find = array( "/\[img\]http\:\/\/img\.youtube.com\/vi\/(.+?)\/0\.jpg\[\/img\]/is", //youtube videos done by the old tinymce plugin... "/\[img\](.+?)\[\/img\]/is", "/\[img=([0-9]+)x([0-9]+)\](.+?)\[\/img\]/is", "/\[media=youtube\](.+?)\[\/media\]/is", // This is for videos done by xenforo... "/\[youtube\](.+?)\[\/youtube\]/is" ); $replace = array( "<iframe class=\"youtube-player\" width=\"100%\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen> </iframe>", "<img src=\"$1\" class=\"bbcodeimage-comment img-polaroid\" alt=\"[img]\" />", "<img width=\"$1\" height=\"$2\" src=\"$3\" class=\"bbcodeimage-comment img-polaroid\" alt=\"[img]\" />", "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", // for xenforo videos "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>" ); $body = preg_replace($find, $replace, $body); } // get rid of empty BBCode, is there a point in having excess markup? $body = preg_replace("`\[(b|i|s|u|url|mail|img|quote|code|color|youtube)\]\[/(b|i|s|u|url|mail|img|quote|code|color|youtube)\]`",'',$body); $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is", "/\[b\](.+?)\[\/b\]/is", "/\[i\](.+?)\[\/i\]/is", "/\[u\](.+?)\[\/u\]/is", "/\[s\](.+?)\[\/s\]/is", "/\[color\=(.+?)\](.+?)\[\/color\]/is", "/\[font\=(.+?)\](.+?)\[\/font\]/is", "/\[center\](.+?)\[\/center\]/is", "/\[right\](.+?)\[\/right\]/is", "/\[left\](.+?)\[\/left\]/is", "/\[img\]http\:\/\/img\.youtube.com\/vi\/(.+?)\/0\.jpg\[\/img\]/is", //youtube videos done by the old tinymce plugin... "/\[img\](.+?)\[\/img\]/is", "/\[img=([0-9]+)x([0-9]+)\](.+?)\[\/img\]/is", "/\[email\](.+?)\[\/email\]/is", "/\[s\](.+?)\[\/s\]/is", "/\[media=youtube\](.+?)\[\/media\]/is", // This is for videos done by xenforo... "/\[youtube\](.+?)\[\/youtube\]/is", '/\[list\](.*?)\[\/list\]/is', '/\[\*\](.*?)(\n|\r\n?)/is', '/\[ul\]/is', '/\[\/ul\]/is', '/\[li\]/is', '/\[\/li\]/is', "/\[size\=(.+?)\](.+?)\[\/size\]/is", "/\[email\=(.+?)\](.+?)\[\/email\]/is", "/\[justify\](.+?)\[\/justify\]/is", "/\[code\](.+?)\[\/code\]/is", "/\[sup\](.+?)\[\/sup\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>", "<strong>$1</strong>", "<em>$1</em>", "<span style=\"text-decoration:underline;\">$1</span>", "<del>$1</del>", "$2", "$2", "<div style=\"text-align:center;\">$1</div>", "<div style=\"text-align:right;\">$1</div>", "<div style=\"text-align:left;\">$1</div>", "<iframe class=\"youtube-player\" width=\"100%\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen> </iframe>", "<a class=\"fancybox\" rel=\"group\" href=\"$1\"><img src=\"$1\" class=\"bbcodeimage img-polaroid\" alt=\"[img]\" /></a>", "<a class=\"fancybox\" rel=\"group\" href=\"$3\"><img width=\"$1\" height=\"$2\" src=\"$3\" class=\"bbcodeimage img-polaroid\" alt=\"[img]\" /></a>", "<a href=\"mailto:$1\" target=\"_blank\">$1</a>", "<span style=\"text-decoration: line-through\">$1</span>", "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", // for xenforo videos "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", '<ul>$1</ul>', '<li>$1</li>', '<ul>', '</ul>', '<li>', '</li>', '$2', '<a href="mailto:$1">$2</a>', '$1', 'Code:<br /><code>$1</code>', '<sup>$1</sup>' ); $smilies = array( ":><:" => '<img src="/includes/jscripts/sce/emoticons/angry.png" data-sceditor-emoticon=":><:" alt="" />', ":><:" => '<img src="/includes/jscripts/sce/emoticons/angry.png" data-sceditor-emoticon=":><:" alt="" />', // for comments as they are made html-safe ":'(" => '<img src="/includes/jscripts/sce/emoticons/cry.png" data-sceditor-emoticon=":\'(" alt="" />', // for comments as they are made html-safe ":'(" => '<img src="/includes/jscripts/sce/emoticons/cry.png" data-sceditor-emoticon=":'(" alt="" />', ":dizzy:" => '<img src="/includes/jscripts/sce/emoticons/dizzy.png" data-sceditor-emoticon=":dizzy:" alt="" />', ":D" => '<img src="/includes/jscripts/sce/emoticons/grin.png" data-sceditor-emoticon=":D" alt="" />', "^_^" => '<img src="/includes/jscripts/sce/emoticons/happy.png" data-sceditor-emoticon="^_^" alt="" />', "<3" => '<img src="/includes/jscripts/sce/emoticons/heart.png" data-sceditor-emoticon="<3" alt="" />', "<3" => '<img src="/includes/jscripts/sce/emoticons/heart.png" data-sceditor-emoticon="<3" alt="" />', // for comments as they are made html-safe ":huh:" => '<img src="/includes/jscripts/sce/emoticons/huh.png" data-sceditor-emoticon=":huh:" alt="" />', ":|" => '<img src="/includes/jscripts/sce/emoticons/pouty.png" data-sceditor-emoticon=":|" alt="" />', ":(" => '<img src="/includes/jscripts/sce/emoticons/sad.png" data-sceditor-emoticon=":(" alt=""/>', ":O" => '<img src="/includes/jscripts/sce/emoticons/shocked.png" data-sceditor-emoticon=":O" alt="" />', ":sick:" => '<img src="/includes/jscripts/sce/emoticons/sick.png" data-sceditor-emoticon=":sick:" alt="" />', ":)" => '<img src="/includes/jscripts/sce/emoticons/smile.png" data-sceditor-emoticon=":)" alt="" />', ":P" => '<img src="/includes/jscripts/sce/emoticons/tongue.png" data-sceditor-emoticon=":P" alt="" />', ":S:" => '<img src="/includes/jscripts/sce/emoticons/unsure.png" data-sceditor-emoticon=":S" alt="" />', ":woot:" => '<img src="/includes/jscripts/sce/emoticons/w00t.png" data-sceditor-emoticon=":woot:" alt="" />', ":whistle:" => '<img src="/includes/jscripts/sce/emoticons/whistle.png" data-sceditor-emoticon=":whistle:" alt="" />', ";)" => '<img src="/includes/jscripts/sce/emoticons/wink.png" data-sceditor-emoticon=";)" alt="" />', ":wub:" => '<img src="/includes/jscripts/sce/emoticons/wub.png" data-sceditor-emoticon=":wub:" alt="" />' ); $body = str_replace( array_keys( $smilies ), array_values( $smilies ), $body ); $body = preg_replace($find, $replace, $body); $body = nl2br($body); // stop there being a big gap between list items $body = str_replace('</li><br />', '</li>', $body); // stop there being a big gap after a list is finished $body = str_replace('</ul><br />', '</ul>', $body); // stop big gaps after embedding a tweet from twitter $body = str_replace('</a></blockquote><br />', '</a></blockquote>', $body); $body = str_replace('</script><br />', '</script>', $body); return $body; } Completely stuck on how I can achieve this
  7. I found the error, i changed the uploader code to this: function upload_item($item_id) { global $site_config, $db_pxs, $lang, $pxs, $error, $filename; $error = ''; // first we check if it is allowed $allowed_extensions = array('image/jpeg'); if (in_array($_FILES['new_upload']['type'], $allowed_extensions)) { // check file size not bigger than 1.47mb if ($_FILES['new_upload']['size'] > 1542000) { $error = 'Sorry file is too big!'; return false; } // THE MAIN FILE // give the file a random file name $filename = rand() . 'id' . $item_id . $_FILES['new_upload']['name']; // the actual file $source = $_FILES['new_upload']['tmp_name']; // where to upload to $target = "uploads/" . $filename; // if (move_uploaded_file($source, $target)) { return true; } else { $error = 'Could not upload file, please contact the admin!'; return false; } } else { $error = 'Wrong file type, allowed to upload .jpg files only.'; return false; } }
  8. That will do nothing, "admin_error" outputs a css error box "$error" is the error message. I do appreciate the help, but like i said it already works for the other error messages like i stated.
  9. Actually it will only show the error if this happens: if (upload_item($db_pxs->last_id()) == false) The only times it is returned false is when there is an a error message set.
  10. The other block is not in a function no it prints out the other error messages fine. I've tried to do some debugging but i cannot figure it out so i posted here.
  11. Basically my image upload seems to work fine, it uploads the image in question ive tested that a few times, but it seems to then return with a blank error message. Here is my code: function upload_item($item_id) { global $site_config, $db_pxs, $lang, $pxs, $error; $error = ''; // first we check if it is allowed $allowed_extensions = array('image/jpeg'); if (in_array($_FILES['new_upload']['type'], $allowed_extensions)) { // check file size not bigger than 1.47mb if ($_FILES['new_upload']['size'] > 1542000) { $error = 'Sorry file is too big!'; return false; } // THE MAIN FILE // give the file a random file name $filename = rand() . 'id' . $item_id . $_FILES['new_upload']['name']; // the actual file $source = $_FILES['new_upload']['tmp_name']; // where to upload to $target = "uploads/" . $filename; // if (move_uploaded_file($source, $target)) { return $filename; } else { $error = 'Could not upload file, please contact the admin!'; return false; } } else { $error = 'Wrong file type, allowed to upload .jpg files only.'; return false; } } The image appears in my upload directory fine. I don't see why it gives a blank error, i set only 3 error messages possible? Here is the checking code: // initial screenshot if ($_FILES['new_upload']['error'] == UPLOAD_ERR_OK) { if (upload_item($db_pxs->last_id()) == false) { $pxs->admin_error($error); } $screenshot_sql = "INSERT INTO `item_screenshots` SET `item_id` = {$db_pxs->last_id()}, `image` = '{$filename}'"; $query_shot = $db_pxs->query($screenshot_sql); } It doesn't seem to get to the screenshot sql, giving a blank error message above , yet it does upload the file :S Any help would be great!
  12. Well it is apparently this line causing the problem: Any ideas??
  13. What is the 6143? I have tried with E_ALL but it comes up with crappy variables not set, no actual real errors.
  14. I have a script that basically checks paypal for a payment, then does a few queries, mails me and then should include the index page, but it doesn't, it does everything else but include my index page, the page in question is attatched and so is the index page. I hope someone can, my host or friend could not come up with an answer [attachment deleted by admin]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.