@@ -11,16 +11,11 @@ public function __construct()
1111 $ this ->load ->model ('users_to_marks_model ' , 'user_marks ' );
1212 }
1313
14- public function add_by_url ()
15- {
16- // Figure view
17- $ this ->figureView ('marks/add_by_url ' );
18- }
19-
2014 /*
21- - Add a mark
15+ - Add a mark
2216 - URLS
2317 /mark/add
18+ /mark/add/?url=URL
2419 /api/mark/add
2520
2621 // Query variables
@@ -34,38 +29,52 @@ public function add()
3429 $ view = null ;
3530 $ add_from_url = ($ this ->input ->post ('add_from_url ' ) !== null ) ? true : false ;
3631
32+ if ( isset ($ _GET ['url ' ]) && !isset ($ _GET ['title ' ]) ) {
33+ $ add_from_url = true ;
34+ }
35+
3736 if ( $ add_from_url ) : // URL submitted by form within app
38- $ url = $ this ->input ->post ('url ' );
39- if (!preg_match ("~^(?:f|ht)tps?://~i " , $ url )) { // Adds HTTP if needed
40- $ url = "http:// " . $ url ;
41- }
42- $ title = '' ;
43- $ dom = new DOMDocument ();
44- libxml_use_internal_errors (true );
45- if (!$ dom ->loadHTMLFile ($ url , LIBXML_NOWARNING )) {
46- foreach (libxml_get_errors () as $ error ) {
47- // handle errors here
48- echo '<p>There was an error adding the mark.</p> ' ;
49- if ( $ error ->code == 1549 ) {
50- echo '<p>Most likely the URL is invalid or the web site isn \'t currently available.</p> ' ;
51- }
52- //print_r($error);
5337
54- }
55- libxml_clear_errors ();
38+ $ url = (isset ($ _GET ['url ' ])) ? $ this ->input ->get ('url ' ) : $ this ->input ->post ('url ' );
39+
40+ if ( !$ url || $ url == '' ) :
41+ echo '<a href="/">BACK</a> - Please supply an URL. ' ;
5642 exit ;
57-
58- } else {
59- $ list = $ dom ->getElementsByTagName ("title " );
60- if ($ list ->length > 0 ) {
61- $ title = $ list ->item (0 )->textContent ;
62- }
63- }
64-
65- if ( strlen ($ title ) == 0 ) :
66- $ title = "Unknown Page Title " ;
6743 endif ;
6844
45+ if (!preg_match ("~^(?:f|ht)tps?://~i " , $ url )) : // Adds HTTP if needed
46+ $ url = "http:// " . $ url ;
47+ endif ;
48+
49+ $ title = (isset ($ _GET ['title ' ])) ? $ this ->input ->get ('title ' ) : '' ; // If title is supplied, use that
50+
51+ if ( $ title == '' ) : // If title is empty, go get it
52+ $ dom = new DOMDocument ();
53+ libxml_use_internal_errors (true );
54+ if (!$ dom ->loadHTMLFile ($ url , LIBXML_NOWARNING )) :
55+ foreach (libxml_get_errors () as $ error ) :
56+ // handle errors here
57+ echo '<p><a href="/">BACK</a> There was an error adding the mark.</p> ' ;
58+ if ( $ error ->code == 1549 ) :
59+ echo '<p>Most likely the URL is invalid or the web site isn \'t currently available.</p> ' ;
60+ endif ;
61+ endforeach ;
62+ libxml_clear_errors ();
63+ exit ;
64+
65+ else :
66+ $ list = $ dom ->getElementsByTagName ("title " );
67+ if ($ list ->length > 0 ) :
68+ $ title = $ list ->item (0 )->textContent ;
69+ endif ;
70+ endif ;
71+
72+ if ( strlen ($ title ) == 0 ) :
73+ $ title = "Unknown Page Title " ;
74+ endif ;
75+
76+ endif ; // end if empty title
77+
6978 else : // URL submitted via bookmarklet, API, or mobile app
7079 $ url = (isset ($ this ->db_clean ->url )) ? $ this ->db_clean ->url : null ;
7180 $ title = (isset ($ this ->db_clean ->title )) ? $ this ->db_clean ->title : null ;
@@ -253,19 +262,33 @@ public function edit($mark_id=0)
253262 $ options ['notes ' ] = $ this ->db_clean ->notes ;
254263
255264 // Check for hashmarks to tags
256- $ tags = getTagsFromHash ($ options ['notes ' ]);
265+ //Removed in 2.0 $tags = getTagsFromHash($options['notes']);
266+ }
267+
268+ // If tags are present, set them
269+ if (isset ($ this ->db_clean ->tags )) {
270+ if ( $ this ->db_clean ->tags == 'unmark:removeAllTags ' ) { // Remove all tags by sending empty array
271+ $ tags = array ();
272+ parent ::removeTags ($ mark_id );
273+ } else {
274+ $ tags = explode ( ', ' , $ this ->db_clean ->tags );
275+ }
257276 }
258277
259278 // If tags are present, handle differently
260279 // Need to add to tags table first
261280 // Then create association
262281 // If notes are present set them
263- if (isset ($ tags )) {
282+ if (isset ($ tags ) && count ( $ tags ) > 0 ) {
264283 parent ::addTags ($ tags , $ mark_id );
265284 }
266285
267- // Update users_to_marks record
268- $ mark = $ this ->user_marks ->update ("users_to_marks.user_id = ' " . $ this ->user_id . "' AND users_to_marks.users_to_mark_id = ' " . $ mark_id . "' " , $ options );
286+ if ( isset ($ options ) && count ($ options ) > 0 ) {
287+ // Update users_to_marks record
288+ $ mark = $ this ->user_marks ->update ("users_to_marks.user_id = ' " . $ this ->user_id . "' AND users_to_marks.users_to_mark_id = ' " . $ mark_id . "' " , $ options );
289+ } else {
290+ $ mark = $ this ->user_marks ->readComplete ($ mark_id );
291+ }
269292
270293 // Check if it was updated
271294 if ($ mark === false ) {
@@ -313,6 +336,8 @@ public function edit($mark_id=0)
313336
314337 public function get ($ what ='stats ' )
315338 {
339+ log_message ( 'DEBUG ' , 'Running get method for ' . $ what );
340+
316341 parent ::redirectIfWebView ();
317342 $ method = 'get ' . ucwords ($ what );
318343
@@ -384,13 +409,14 @@ private function getStats()
384409
385410 }
386411
387- // Get the 10 most used tags for a user
412+ // Get the 10 most used and most recent tags for a user
388413 private function getTags ()
389414 {
390- $ this ->data ['tags ' ] = array ();
391415 $ this ->load ->model ('user_marks_to_tags_model ' , 'user_tags ' );
392- $ this ->data ['tags ' ]['popular ' ] = $ this ->user_tags ->getPopular ($ this ->user_id );
393- $ this ->data ['tags ' ]['recent ' ] = $ this ->user_tags ->getMostRecent ($ this ->user_id );
416+ $ this ->data ['tags ' ] = array ();
417+
418+ $ this ->data ['tags ' ]['popular ' ] = $ this ->user_tags ->getPopular ($ this ->user_id );
419+ $ this ->data ['tags ' ]['recent ' ] = $ this ->user_tags ->getMostRecent ($ this ->user_id );
394420 }
395421
396422 // The index of the marks page
@@ -575,7 +601,7 @@ public function index()
575601 // Get stats, labels and tags
576602 // else skip this section and just return the marks
577603 if (parent ::isWebView () === true ) {
578- self ::getStats ();
604+ // self::getStats();
579605 self ::getLabels ();
580606 self ::getTags ();
581607 }
@@ -611,11 +637,10 @@ public function info($mark_id=0)
611637 $ this ->data ['no_header ' ] = true ;
612638 $ this ->data ['no_footer ' ] = true ;
613639
614- // print_r($_GET['bookmarklet']);
615- // exit;
616-
617640 $ this ->data ['bookmarklet ' ] = (isset ($ _GET ['bookmarklet ' ])) ? $ _GET ['bookmarklet ' ] : true ;
618641
642+ self ::getTags ();
643+
619644 // Figure view
620645 $ this ->figureView ('marks/info ' );
621646 }
0 commit comments