Jump to content

EyeDentify

Members
  • Content Count

    99
  • Joined

  • Last visited

  • Days Won

    2

EyeDentify last won the day on February 10 2016

EyeDentify had the most liked content!

Community Reputation

93 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,802 profile views
  1. Your Welcome. It´s kind of my thing to try to keep things simple and understandable. Not just for myself but also so other could have use for my code. I will think about the GDPR issue. Have a nice day.
  2. Hello Fellow PW fans. Tought i share a simple but usefull way of utilizing the $log system in PW to do simple loging on what IP visit the site and also the HOST. Its not fancy, and its very basic, see it as a boiler plate. You can get all kinds of fancy with it. Remember that the $log system automaticly records the URL from where it was called so we don´t need to supply that to our Entry. I just wanted a simple entry with IP and HOST, the date is also recorded with the entry automaticly. The beauty is that i can watch the logs from the ADMIN page almost in realtime. I am using the "markup regions" output method so i put the code in my _main.php file. You could just put it wherever like to be included with every page load in your site. I hardcoded my logfile to be named ip_log_site but you can use what you feel is better. Also made sure the loging do not happen if your logged in as admin (Super user). See this PW Doc for more info: https://processwire.com/api/ref/wire-log/save/ <?PHP function logIP($session, $log) { /* get IP info */ $ip_adress = $session->getIP(); $host_address = gethostbyaddr($ip_adress); /* log IP adress info NOTE: 'ip_log_site' is a hardcoded name of the logfile, change for your preference. */ $log->save("ip_log_site", "IP: {$ip_adress}, Host: {$host_address}"); } /* if Super User (Admin) do not log */ if(!$user->isSuperuser()) { logIP($session, $log); } ?> Hope anyone have use for it. /EyeDentify
  3. <?PHP /* single out with selectors the pages you want to target */ $pageArray = $pages->findMany('template=name_of_template, field_name=value); /* iterate through the selected pages and do something to each of them */ foreach($pageArray AS $key => $myPage) { /* Do something with the page */ } ?> Also check out the documentation for Selectors. They are very powerfull and usefull. https://processwire.com/docs/selectors/ Also check out the API docs for $page https://processwire.com/api/ref/page/ And $pages https://processwire.com/api/ref/pages/ The API docs are my first stop when i am trying to figure out to do something in PW. Good luck.
  4. Thats great for you. But still nothing in the documentation suggests that it´s obvious just because its a method of $page. It´s says the data is independent of the fields of the page and such lead me to belive i could call $page->meta() from any page and get the data back that i saved. Anyhow, this post is for the people who don´t think its obvious. We are all different. But thank you for your input Markus. have a nice day and happy coding.
  5. I have been experimenting with the new $page->meta() method and find it useful. Once i figured out that the data i "save" with it is tied to the page where i called the method from. So this is not obvious at least not for me in the documentation: https://processwire.com/api/ref/page/meta/ So i just wanted to share that revelation with the community so you don´t get as confused as i was. Happy Coding Everyone.
  6. 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
  7. 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
  8. 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.
  9. 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.
  10. Oki. I have to do some testing but i think i got the gist of it.
  11. 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.
  12. 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?
  13. 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. 🙂
  14. 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?
  15. 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
×
×
  • Create New...