Jump to content

EyeDentify

Members
  • Content Count

    94
  • Joined

  • Last visited

  • Days Won

    2

EyeDentify last won the day on February 10 2016

EyeDentify had the most liked content!

Community Reputation

87 Excellent

About EyeDentify

  • Rank
    Full Member
  • Birthday 07/15/1979

Profile Information

  • Gender
    Male
  • Location
    Sweden
  • Interests
    Web programming and design. cooking. Movies. Photography and more.

Recent Profile Visitors

1,690 profile views
  1. i Would like to thank everyone who gave me tips and advice on this topic. Think i got the gist of it and i will certainly consider everything mentioned. :) /EyeDentify
  2. Hello There Guys. I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here. I was wondering how i could use an external library, lets say TwitterOAuth in my PW module. Link to library https://twitteroauth.com/ Would the code below be correct or how would i go about this: <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree? I don´t need a complete solution, i just wonder if i am including the external library the right way. If not, then give me a few hint´s and i will figure it out. Thanks a bunch. /EyeDentify
  3. Hello There Fellow PW lovers. I wanted to share this code that i created to post tweets to the Twitter API in an upcomming project i am working on. And i Thought that everyone could have some use for it. I am using Composer to load the TwitterOAuth PHP library for working with the Twitter API in this code example. Also you need to create an App and have your own API keys ready, you can do that here: https://developer.twitter.com/en/apps The code posts a string and uploads media to be used with the tweet. For the TwitterOAuth methods information see the link above. Note: The paths to the media needs to be local for TwitterOAuth to pick them up and upload them. See this link for filesize limits and other info on media attachements. https://developer.twitter.com/en/docs/media/upload-media/overview <?PHP /* TwitterOAuth API via Composer https://twitteroauth.com/ */ include('vendor/autoload.php'); /* define the classes */ use Abraham\TwitterOAuth\TwitterOAuth; function postTweetUpdate($str = '', $mediaArray = null) { /* Twitter OAuth keys Create your App and find your API keys here: https://developer.twitter.com/en/apps */ $consumer_key = ''; $consumer_secret = ''; $access_token = ''; $access_token_secret = ''; /* init API */ $connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret); if(is_array($mediaArray)) { $mediaIDS = array(); /* Up to 4 media objects can be uploaded. https://developer.twitter.com/en/docs/media/upload-media/overview */ foreach($mediaArray AS $key => $media_path) { /* Upload media to twitter API and get media ID back */ $mediaOBJ = $connection->upload('media/upload', ['media' => $media_path]); /* push uploaded media ID to array */ array_push($mediaIDS, $mediaOBJ->media_id_string); } /* create comma delimited list of media ID:s */ $mediaIDstr = implode(',', $mediaIDS); } /* API params */ $arrayCfg['status'] = $str; $arrayCfg['media_ids'] = $mediaIDstr; /* Make POST request to Twitter API https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update */ $statuses = $connection->post("statuses/update", $arrayCfg); /* return payload */ return $statuses; } ?> <?PHP /* string to Post */ $str = 'Test Tweet... ' . PHP_EOL; $str .= '#mytweet' . PHP_EOL; $str .= 'http://www.mywebsite.com' . PHP_EOL; $str .= '' . hash('sha1', mt_rand(0, 1000000)); /* media to upload */ $mediaToUpload[] = 'images/my_image.jpg'; /* make request to Twitter API */ $payLoad = postTweetUpdate($str, $mediaToUpload); ?> <h3>Debug</h3> <pre><?PHP print_r($payLoad); ?></pre> I have the Debug part because its handy to see what is returned from the Twitter API.
  4. Thanks to bernhard and Autofahrn i have come up with this example code and run it in TracyDebugger on a test page with a image field and it works beautifully. <?PHP /* get and save a new image to image field Pageimages array */ $page->of(false); $pageImages = $page->images->add('https://www.somesite.com/image_of_tree.jpg'); /* save the page (perhaps not needed but there for comfort.) */ $page->save(); /* get the last added image */ $lastImage = $page->images->last(); /* debug before changes */ d($lastImage, '$lastImage before changes'); /* add tags to the image and description */ $lastImage->addTag('test'); $lastImage->addTag('Tree'); $lastImage->addTag('Syren'); $lastImage->addTag('Sun'); $lastImage->addTag('Sunny'); $lastImage->description = 'This is a beautiful tree.'; /* debug info */ d($page->images, '$page->images'); d($lastImage, '$lastImage'); /* save the page */ $page->save(); ?> I used the following API docs and mentioned forums users help to accomplish this: https://processwire.com/api/ref/pageimage/ https://processwire.com/api/ref/pageimages/ https://processwire.com/api/ref/pagefile/ https://processwire.com/api/ref/pagefiles/ Just wanted to post this at the end so others who wonder about this could get a starting point.
  5. Oki. I have to do some testing but i think i got the gist of it.
  6. Thanks to Everyone involved with helping me on this subject. Sometimes you can get confused and then need another set of eyes on the problem to figure it out.
  7. Ok i got it. But i was refering to changing the Pageimage obj properties that was newly created: https://processwire.com/api/ref/pageimage/#api-construct And then save it. But maybe i should save it, find it, change it and then save it again?
  8. I do have TracyDebugger installed, but i did not know i could do that in the TracyDebugger You learn something new everyday. Thank you all for helping me understand this.
  9. Yes ofcourse Sir Forgot about the output formating But otherwise it seems allright? Could i expect to access the newly created Pageimage object as a return value from: <?PHP $urlToImage = 'http://www.somesite.com/image.jpg'; $pageImageObj = $page->images->add($urlToImage); ?> And do some changes to it before saving or should one save in between?
  10. Hello Gentlemen and Ladies. I have not posted for a while but now i need your help figuring out some things. The Documentation has come a long way and i love it. Though on the page: https://processwire.com/api/ref/pageimages/ I am trying to figure out if when i want to add an image to an existing image field with multiple images alldready in it and using the method $page->images->add() <?PHP /* get the images object array for the Page */ $myPageImg = $page->images; /* define the image to add */ $newImg = 'http://www.somesite.com/image.jpg'; /* Thanks Autofahrn, forgot about the output formating */ $page->of(false); /* create a new Pageimage object with the given URL and add to the Pageimages array */ $myPageImg->add($newImg); /* save the page */ $page->save(); ?> I am pretty sure i missed a few steps in the code above? Is that string suppose to be an URL like "http://www.somesite.com/image.jpg" and the method will automaticly download the image and create an Pageimage Object and add it to Pageimages array or does it have to exist on the host first and i supply a file path to that image? I guess im confused about that, hope you guys could clarify that for me. And if it needs to be allready downloaded to my host before adding the image, what would be the best API methods for that task? Just point me in the right direction and i will figure it out. Sorry for the bad explaination but i could not figure out a better way of asking. Thanks in advance. /EyeDentify
  11. I must say that i am very much in love with where the new site is going and specificly the Document section. And finaly a section that explains the "Markup Regions" Enjoying that section very much because i have planned for a long time to move over to using Markup Regions, but with the information scatterd all over the forums and the old site it was hard to get a complete grasp on the inner workings. Now i think with the new Documents section its pretty crystal clear how it works. Thank You Ryan and everyone working hard on the new site. Looking forward to the release when its finished.
  12. No Worries. Indeed its a fairly new API. You can also check it out in the source code at: https://github.com/processwire/processwire/blob/master/wire/core/FunctionsAPI.php For more details. Hope you find it useful. Cheers.
  13. I as have been a bit confused for some time about how the "Markup Regions" functionality in Processwire worked. But i have know read a bit more and think that i am getting to grips with it. And Markup Regions is going to be huge. To aid me in understanding Markup Regions better i started to read the Source code for the new "Regular" theme in conjunction with the Blog about the markup regions. It helped me a great deal to understand the basics and more fine details of it. A tip is to open both links and use the Source code of the "Regular" theme while reading the blog post. The Source code: https://github.com/processwire/processwire/blob/dev/site-regular/templates/_main.php The Blog post: https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/ I hope this could help others starting out with markup regions. Just take it slow and read it a couple a times and soon you will see the greatness of markup regions. /EyeDentify
  14. Support for HTTPS is enabled by default in Processwire. Making SSL work with your hosting is a Certificate issue. Check out the letsencrypt.org website for more info.
  15. Hey @ryan I was woundering if you would recommend that one save the Page once, before trying to add files for upload and then save again? I think you mentioned that in some thread? Or is this not necessary anymore?
×
×
  • Create New...