
    oi&                        d dl mZmZmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlZd dlZd dlZd dlZd dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ  e            Z ee          Z ej        e          Z  eddg          Z! ed          Z"d Z#d Z$de%de%fdZ& ee!ddge           ee           ee          fdefd            Z' ee!ddge           ee          fdefd            Z(dS )    )	APIRouterRequestDepends)RedirectResponseHTMLResponse)Jinja2Templates)HTTP_302_FOUND)datetimeN)urlparse)get_current_user)get_pingconf_vars
open_mysqlget_mysql_creds)nav_context)add_dual_routez/postarticlepostarticle)prefixtags	templates)	directoryc                     t          t                    5 } |                     d          }|                    d           |                                }|                                 d d d            n# 1 swxY w Y   |S )NT)
dictionaryz7SELECT CatNum, CatName FROM Categories ORDER BY CatName)r   mysql_credscursorexecutefetchallclose)connr   resultss      ./wd/v2025.freedom4um.com/routes/postarticle.pyget_categories_from_dbr!      s    	K	 	  D--E	
 	
 	
 //##               Ns   AA55A9<A9c                     | dk    s|dk    r|S t          |          }|j        pd                                }h d}||v r|ndS )z'Restrict iframe src to allowed domains.iframesrc >   youtu.be
rumble.comyoutube.combitchute.comwww.rumble.comwww.youtube.comwww.bitchute.comN)r   netloclower)tagattrvalueparsedhostalloweds         r    safe_iframe_srcr5   )   s`    
h$%--e__FMR&&((D  G GOO55-    	body_textreturnc                     d}d}d}d}t          j        d|           r| S t          j        |d |           } t          j        |d |           } t          j        |d |           } t          j        |d	 |           } | S )
z
    Convert bare video/image URLs into embed wrappers
    if the user did not already insert HTML.
    Mirrors /postcomment behavior.
    zk(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?|shorts)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})z0bitchute\.com\/(?:video|embed)\/([a-zA-Z0-9_-]+)z:rumble\.com\/(?:v|embed\/v)([a-zA-Z0-9_-]{6,})(?:-[^\/]+)?z2(https?:\/\/[^\s<>"\']+\.(?:jpg|jpeg|png|gif|bmp))z<(?:iframe|img|div)c                 4    d|                      d           dS )Nzw<div class="video-wrapper" contenteditable="false"><iframe width="640" height="360" src="https://www.youtube.com/embed/   z1" frameborder="0" allowfullscreen></iframe></div>groupms    r    <lambda>z'process_media_content.<locals>.<lambda>J   s(    23''!**   r6   c                 4    d|                      d           dS )Nzx<div class="video-wrapper" contenteditable="false"><iframe width="640" height="480" src="https://www.bitchute.com/embed/r;   z2/" frameborder="0" allowfullscreen></iframe></div>r<   r>   s    r    r@   z'process_media_content.<locals>.<lambda>V   s(    34771::   r6   c                 4    d|                      d           dS )Nzs<div class="video-wrapper" contenteditable="false"><iframe width="640" height="360" src="https://rumble.com/embed/vr;   z8/?pub=4" frameborder="0" allowfullscreen></iframe></div>r<   r>   s    r    r@   z'process_media_content.<locals>.<lambda>b   s(    ./ggajj   r6   c                 4    d|                      d           dS )Nz=<div class="image-wrapper" contenteditable="false"><img src="r;   z" alt="" width="400"></div>r<   r>   s    r    r@   z'process_media_content.<locals>.<lambda>n   s(       r6   )researchsub)r7   youtube_regexbitchute_regexrumble_regeximage_regexs        r    process_media_contentrK   :   s     CMHNPLGK	y'33 	
 	
 	
 
I 	
 	
 	
 
I 	
 	
 	
 
I 	
 	

 	 I r6   r%   GET)methodsresponse_classrequestc                 X  K   |st          dt                    S t          j                    }d t	          dd          D             }t          t	          dd                    }t                              d| t                      |||j	        |j
        |j        ddddddi |d|          S )	N/signinc                 8    g | ]}|t           j        |         d S )numnamecalendar
month_abbr.0is     r    
<listcomp>z$postarticle_form.<locals>.<listcomp>   s(    OOOQa!4Q!788OOOr6   r;          postarticle.htmlr%   rO   
categoriesmonthsdayspublish_yearpublish_monthpublish_daytitlecategorysource
url_sourceauthorarticleerrorsuser)r   r	   r
   nowrangelistr   TemplateResponser!   yearmonthday)rO   rn   navcurrent_daterb   rc   s         r    postarticle_formrx   }   s        ;	>:::<>>LOO%2,,OOOFaD%%022(-)/'+	
 	
  !	
  r6   POSTc                 	  K   t                               d           |st          dt                    S |                                  d {V }|                    d          pd                                }|                    d          pd                                }|                    d          pd                                }|                    d          pd                                }|                    d          pd                                }|                    d	          pd                                }|                    d
          }	|                    d          }
|                    d          }i }|sd|d<   |sd|d<   |                                sd|d<   	 t          |	          ddt          |
          ddt          |          d}n# t          $ r
 d|d<   d }Y nw xY wt          j        dd|                                          }t          t          j        d|t          j                            }|s|sd|d<   |rt          |            d {V }t!          j                    }d t%          dd          D             }t'          t%          dd                    }t(                              d| t-                      |||j        |j        |j        ||||||||d|          S 	 t5          |          }t7          j        |g dg d g d!d"gd#d$d%gd&'          }t!          j                                        d(          }t=          t>                    5 }|                                 }|!                    d)|d*         t          |          |||||||f	           |"                                 |j#        }|!                    d+|d*         |||f           |"                                 d d d            n# 1 swxY w Y   t          d,| d-t          .          S # t          $ r|}t           $                    d/           t          |            d {V }t(                              d| t-                      ||||||d0tK          |          i|d1
|          cY d }~S d }~ww xY w)2Nz*=== POSTARTICLE_SUBMIT FUNCTION CALLED ===rQ   rg   r%   rh   ri   rj   rk   rl   rd   re   rf   zTitle is required.zAuthor is required.zPlease select a valid category.04d-02dzInvalid publish date.publish_datez<[^>]*>z<(?:img|iframe)\bzArticle content is required.contentc                 8    g | ]}|t           j        |         d S rS   rV   rY   s     r    r\   z&postarticle_submit.<locals>.<listcomp>   s(    SSS!X%8%;<<SSSr6   r;   r]   r^   r_   r`   )br[   ubrpdivimgr#   )r$   altwidthheight)r$   r   r   frameborderallowfullscreenclass)r   r#   r   httphttpsT)r   
attributes	protocolsstripz%Y-%m-%d %H:%M:%Sz
                INSERT INTO Articles
                (HandleID, CatNum, PostDate, PubDate, URL, Source, Author, Title, Article)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
                idz
                INSERT INTO Comments
                (HandleID, ArtNum, ComNum, PostDate, Comment, ReplyToComNum, ReplyToHandleStr)
                VALUES (%s, %s, 0, %s, %s, 0, '')
                z/readarticle?ArtNum=z#C0)urlstatus_codezError submitting articleserver)
rO   ra   rg   rh   ri   rj   rk   rl   rm   rn   )&loggerinfor   r	   formgetr   isdigitint	ExceptionrD   rF   boolrE   Ir   r
   ro   rp   rq   r   rr   r!   rs   rt   ru   rK   bleachcleanstrftimer   r   r   r   commit	lastrowid	exceptionstr)rO   rn   r   rg   rh   ri   rj   rk   article_html_rawpub_year	pub_monthpub_dayrm   pub_date	text_only	has_mediarv   rw   rb   rc   processed_htmlarticle_html	post_dater   r   art_numes                              r    postarticle_submitr      s     
 KK<=== ;	>:::DXXg$"++--E$$*1133Hhhx  &B--//F((<((.B5577Jhhx  &B--//F++1r88::xx''H))Ihh}%%GF /.w 10x ?>z(mmQQQ#i..QQQs7||QQQ   !8~ z2'788>>@@IRY35ErtLLMMI ;Y ;:y 
((((((((|~~SSeArllSSSE!RLL!!))"466  , 1!-!3+/$ ( +    !
 
 	
,R
./?@@ |CCC888VVVy 
 w'

 

 

 LNN++,?@@	$$ &	[[]]FNN JMM 
  $ KKMMM&G NN J	   KKMMMM&	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	P  3w333&
 
 
 	

  
 
 
3444(((((((())"466$ ( +#SVV,  
 
 	
 	
 	
 	
 	
 	
	
sW   -4G" "G65G6A/P7 0BPP7 PP7 PP7 7
R=A1R82R=8R=))fastapir   r   r   fastapi.responsesr   r   fastapi.templatingr   starlette.statusr	   r
   rW   loggingrD   r   urllib.parser   
utils.authr   utils.pingdatar   r   r   	utils.navr   utils.routesr   PingConfr   	getLogger__name__r   routerr   r!   r5   r   rK   rx   r    r6   r    <module>r      s[   / / / / / / / / / / < < < < < < < < . . . . . . + + + + + +         				  ! ! ! ! ! ! ' ' ' ' ' ' I I I I I I I I I I ! ! ! ! ! ! ' ' ' ' ' 'oh''		8	$	$	.	?	?	?Ok222	  . . ."<S <S < < < <F UGLIII 
!	"	"         JI N VH\JJJ 
!	"	"X
 X
X
 X
 X
 KJX
 X
 X
r6   